Python Lesson Two

Source: Internet
Author: User

    1. Variable

you can use it as long as it exists in memory. (Stack)

    1. Ternary operations

name = value 1 if conditions established Else value 2

    1. In-process

Binary octal decimal hexadecimal

Basis

All Things are objects, objects are created by classes

Type dir () help ()

Methods in a class

              __ Method __   private methods, there may be multiple ways of doing it

method has only one method of execution

Digital

ABS () CMP (x, y) coerce (× x) Divmod (y) x//y hash x**y

int (x) long (x) float (x)

STR (x) repr (x)

String

Str.capitalize () str.count (' abc ' [, Start[,end]])

Decode () encode ()

Str.endswith (Suffix[,start[,end]]) Str.startwith (Prefix[,start[,end])

Str.expandtabs ([tabsize]) to be 0 will be deleted when Tab

Str.find (Sub[,star[,end]) could not find the return -1 str.rfind ()

Str.index (Sub[,start[,end]) with the Find similar, but will not be found when the error Str.rindex ()

str1 = ' xxx {0},xxx{1} ' Str.format (' x ', ' y ') bit parameter  

str1 = ' xxx{par1},xxx{par2} ' Str.format (par1= ' xxx ', par2 = ' xxx ') Formal Parameters

str1 = ' xxx {0},xxx{1} ' Str.format (*list) Here's List is made up of parameter values

str1= ' xxx{par1},xxx{par2} ' Str.format (**dict) Here's Dict composition is { ' par1 ': xxx, ' par2 ': XXX }

Str.isalnum () Str.isalpha () Str.isdigit ()

str.islower () str.lower () Str.istitle () Str.title () Str.isupper () Str1.upper () str1.swapcase () uppercase and lowercase swaps

Str.isspace ()

' _ '. Join (str) in _ will be Str the element connection in

Str.center (Width[,fillchar=none]) str.ljust (Width[,fillchar=none]) str.rjust (Width[,fillchar=none])

str.partition (separator) à (Head,separator,tail)-- if the delimited character or string does not exist, it returns Str and two null characters str.rpartition ()

Str.replace (Old,new[,count]))

Str.split (Separator=none[,maxsplit=none]) str.rsplit (Separator=none[,maxsplit=none])

Str.splitlines (Keepends=false)

Str.strip ([chars]) Str.rstrip ([chars]) Str.lstrip ([chars])

str.translate (Trantable[,deletechars])) You need to make a conversion table, and if the conversion table does not exist, delete the string directly from the Deletechars

str.zfile (width) right-aligned, front padding 0

List

List.append (object) list.extend (iterable) Append put Object added to the list as an element, whether it's a string or a list or a dictionary, for Extend , if it is a string, it is broken into a word multibyte to the list, if it is a list, it is broken into a string to add, if it is a dictionary, the Key add it in .  

List.count (value)

List.index (Value[,start[,stop])

List.insert (Index,object)

list.pop ([index]) del List[index] Pop has a return value List.remove (value)

List.reverse () List.sort ()

meta-group

Tuple.count (value) Tuple.index (Value[,start[,stop])

dictionary

Dict.clear ()

dict.copy () Copy only one layer dict = copy.deepcopy (dict1) Deep Copy    -- need more practice

Dict.get (Key[,value=none]) Return , no return to the back. value , the default is None

Dict.fromkeys (List[,value=none]) with List in the worth. Key generates a new dictionary with values for the following value, default is None

Dict.has_key (Key)

Dict.items () Dict.iteritems ()

Dict.keys () dict.values ()

Dict.pop (K[,d=none]) Delete Key to be k value that returns the corresponding value value, if k does not exist, it returns to the back D, otherwise the error

del Dict[k] If it does not exist k , Error

Dict.popitem () remove a key-value pair in an unordered order

Dict.setdefault (k[,d]) equivalent Dict.get (k[,d]) if there is K , it returns the corresponding value, if not, increases Dict[k] = d, If not D , it is equal to None

dict.update (Dict1) with Dict1 to update Dict, If you do not have the same KEY , it increases, if there is, updates, the equivalent Merge

set set ()

Go to the dictionary operation

Submit & | Poor - Reverse Intersection ^

A.issubset (b) a is not b the subset

A.issuperset (b) a is not b the parent set

A.pop () A.remove () a.update (b)

This article is from the "Justforid" blog, make sure to keep this source http://120662.blog.51cto.com/110662/1710480

Python Lesson Two

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.