Program Master File Flag
If __name__== "__main__":
In program execution Python 1.py time program 1.py __name__ to Main
Call other file is, __name__ for program own name equals __name__
All things are objects, objects are created with classes
int internal function
A = 95
b = 10
c = a.__divmod__ (Ten) #分页用到, remainder
Print (c)
(9,5)
A.__GE__ () is greater than or equal to return true, >=
Look at the method of the class
Type () method view types
Dir () See what the methods are
Help () See the Detailed method
name = ' Erwe '
Print (Type (name)) #获取他是什么类. For example, Str,list,int.
Print (dir) #快速获取这个是什么类, listing all the members (functions) within this class.
STR internal elements
Name.__contains__ (' contains element ')
A.__EQ__ () Equality syntax for strings Hall = =
__format__ the formatting of the string,
>>>a = ' eric{0} '
>>>a.__format__ (' Alex ')
>>> A.format (' Alex ')
' Alexalex '
__GETATTRIBUTE__ reflection will use the function
Name.capitalize () Capitalize first letter
Name.casefold () First letter lowercase
Name.center (length, ' **--' ~~__ ')
>>> Print (8* ' * ', a,8* ' * ')
AlExV5 ******** with Center can achieve
>>> A.center (20)
' AlExV5 '
>>> A.center (20, ' * ')
' *******alexv5******* '
Name.count (' element ') calculates the number of occurrences of a repeating element
Name.encode () to encode a string
>>> a = ' Li Jie '
>>> a.encode (' GBK ')
B ' \xc0\xee\xbd\xdc '
Name.endswith (' e ') name is not ending with E
With open (' a.txt ') as F: #用上with管理上下文 without writing f.close ()
F.write ()
String str
removing blank Strip
Split split
Length Len (obj)
Index OBJ[1]
Slice Obj[1:10] 1 represents the second bit. 10 = 10th digit
Lists List
Indexed index
Slice Obj[1:10]
Append Append
Delete del remove pop
Length Len
Loop for, while
Interrupt Break,continue,return (Method return), Exit (program exit)
Contains ' SDFs ' in [SSDFF]
__contains__
Incoming parameters
Import Sys
Print (SYS.ARGV)
How to use Dictionaries
2 ways to create a dictionary
A = {' K1 ', ' v1 '}
A = Dict (k1= ' v1 ')
DIC {"K1": "V1", "K2": "v2"} = = Dict (k1= "v1", K2 = "V2")
Dic.clear Empty
Dic.copy Shallow Copy
Dic.fromkeys ([' K1 '], ' v1 ')
*dic.get (' K1 ') #获取k1的值
Get if key does not exist, return by default (none), no error
Print (Dic.get (' K3 ', ' v3 ')) Assignment of a key method that does not exist
Output
V1
V2
V3
Dic.items () outputs Key,vale at the same time.
For k in Dic.key ():
Print (k)
For V in Dic.values ():
Print (v)
For k,v in items (): #同时输出
Print (K,V)
Getting started with Python next day notes