Base operator
Http://www.cnblogs.com/alex3714/articles/5465198.html
Identity operator: is isn't
Member operator: in No in
# #in to determine if an element exists in the queue that exists in the return ture
A= "ABC"
Print ("B" in a)
num + = 1 equals num = num + 1
num-= 1 equals num = Num-1
num *= 1 equals num = num * 1
num/= 1 equals num = NUM/1
Python logical operator precedence
Not > and > or
Python Common commands
1.input () #交互输入内容 Linux-like read
2.print #打印 print ("Hello World", end= "") #空格为不换行 (can be replaced by other)
3.isdigit () #所有字符都是数字 generally used to determine whether a string is a number
4.count #计算一个字符出现的次数 Print (A.count ("a"))
5.extend #输入一串字符串 split him into a single character-formed list a.extend ("Dsasdqfqfasdafs")
6.index #查找内容的下标 (position) if there are multiple only take the first value of print (A.index ("Q"))
7.reverse #将顺序倒过来没有返回值 A.reverse ()
8.sort #顺序排列列表 numbers (from small to Large) B.sort () string is the order of an ASCII table (first letter)
9.enumerate #顺序排序 (For I in Enumerate (c):) or specify from which sort (for I in Enumerate (c,10):)
10.len #计算列表, Ganso, length of the Dictionary print (len (c)) or print (c.__len__ ())
11.id #数据在内存中存放的地址 (digital) print (ID (a))
12.setdefault #对字典的操作, the original key is not modified, did not create Dic2.setdefault ("age", 12)
13.sorted # #从小到达排序 If the dictionary (number) is the sort letter to the key according to the ASCII sort print (sorted (b))
14.join # #实现字符串的拼接 and can be delimited with specified characters e= "". Join ([A, b]) e= '---'. Join ([a,b,c]) # # RESULTS 123---ABC---123ABC
15.count # #计数 Statistics string Occurrences Print (E.count ("a"))
16.capitalize # #首字母大写 Other letters lowercase print (a.capitalize ())
17.center # #定义字符串的长度 (Insufficient By default fills both ends with blanks) print (A.center (+)) #结果 +++dsadas+++
18.startswith # #判断以什么开头 return bool correctly for Ture print (A.startswith ("D"))
19.
EndsWith # #判断以什么结尾 return bool correctly for Ture print (A.endswith ("s"))
20.find # #查找第一个元素并将索引值返回 Print (A.find ("a")) no Return-1
RFind # #从右往坐寻找索引
21.index # #查找第一个元素并将索引值返回 didn't get an error.
22.format # #格式化输出的另一种方式
A= "Hello World {Name}"
Print (A.format (name= "format"))
Hello World format
23.isdigit # #判断是否为数字 (reshape) correctly returns True
24.islower # #判断是否全小写字母 Print (A.islower ())
25.isupper # #判断是否全大写字母 Print (A.isupper ())
26.isspace # #判断是否为空格 (only space or tab) print (B.isspace ())
27.istitle # #判断是否为标题 (capitalize the first letter of each word) print (A.istitle ())
27.isinstance # #判断类型 Print (Isinstance ([1,2],list))
28.upper # #所有字母大写
29.lower # #所有字母小写
30.swapcase # #大写变小写, lowercase to uppercase
31.strip # #默认将两边空格去掉与换行符, you can remove the specified element
Lstrip # #去掉左边空格与换行符
Rstrip # #右边
32.replace # #替换字符串 Print (A.replace ("as", "QQ"))
33.split # #分割 (can specify split elements and Times) print (A.split ("a"))
34.rsplit # #从右向左分割 Print (A.rsplit ("a", 1)) # # divided 1 times
35.title # #单词的首字母大写其它字母小写
36.encode # #字符集的编码
37.decode # #字符集的解码
The default character in Python2 is ASCII
The default character in Python3 is Unicode #文件编码为utf-8
Python2 If only encode is decoded by default to ASCII #所以编码完记得解码 (decode)
Python3 encode the data into the bytes type while encoding
Decode the bytes type into a string while decoding
Http://www.cnblogs.com/alex3714/articles/5717620.html
Working with files
38.open #操作文件 A=open ("V", ' r ', encoding= ' UTF8 '). Read () ' R ' is to view ' W ' similar to > empty redirect (the contents of the file will be emptied first for W) ' A ' append content like >>
39.read #查看文件
40.white #编辑文件
41.close #关闭文件 (writes buffer data to disk) (writes to disk in Python after the program has finished executing)
42.fileno #查看文件句柄号 (integer)
43.tell #读取当前光标的位置 (English 1:1) (UTF8 Chinese 3:1)
44.seek #定义 (adjust) The position of the cursor A.seek (0)
45.flush #将缓存里的数据写入磁盘
------------------------------
Progress bar
Import Sys,time
For I in range (10):
Sys.stdout.write ("+")
Sys.stdout.flush ()
Time.sleep (0.5)
Method Two,
Import time
For I in range (10):
Print (' "', end= ', flush=true)
Time.sleep (0.5)
------------------------------
46.truncate #保留前面的类容, empty the following class capacity (only in ' a ' maximum mode) #例如 B.truncate (9)/retain the first 9 units of characters
47.eval #字符串表达式的值
48.with #类似close exit with block and save automatically
49.repr #转成方便电脑阅读的字符串 x=repr ("QQQ \ QQQ") #结果 ' QQQ \ n qqq '
50.copy #拷贝数据 (Shallow copy) s1=s.copy () #浅copy只会copy第一层后面共享 (changes to the original data above the second layer will also change)
59.CHR #更具ascii表的号码进行相对应的装换 (uppercase letter A-Z is 65-90) print (CHR) #结果A
Deepcopy #深copy in 51.import copy (clone data)
Import Copy
S=[1,2,5,[555,666]]
S1=copy.deepcopy (s)
s1[3][1]= "XXXXXX"
Print (s1,s)
Set set can be de-weighed (no same data exists)
52.set #可以去重 data type is set set #直接set (' qqw ') result is ' Q ' and ' W ' will go heavy
S=[]
S.extend ("QSADQADSQ")
Print (s)
S1=set (s)
Print (S1,type (S1))
The value within a set data type cannot be hashed (immutable--list---dict)
Set is unordered and non-repeating
##< (contains, must be more than before)
Print (Set ("Qwe") <set ("Qwer") # #set ("Qwe") is set ("Qwer") containing the return true
A= set ([1,2,3,4,5])
b= set ([4,5,6,7,8])
#交集 &
Print (A.intersection (b)) with print (A&B)
#并集 |
Print (A.union (b)) with print (a | b)
#差集 #a里有b里没有的-
Print (A.difference (b)) with print (-a)
#反向差集 (2 sides without each other) ^ (the sharp delivery number)
Print (A.symmetric_difference (b)) with print (A^B)
#超级 (Parent Set) Return Boolean value with <
Print (A.issuperset (b)) with print (A<B)
#子集 > Return boolean value
Print (A.issubset (b)) with print (B>A)
Add to
Add #s1. Add ("UU")
Update
Update #类似extend But the duplicate will only add a
S1.update ("QQQQQE")
Print (S1) #结果 {2, 4, ' e ', ' xxx ', ' q ', ' AA '}
Delete
Remove #s1. Remove ("XXX")
53.*args #无命名参数 (A * parameter that resembles the list's display pass)
**kwargs #有命名参数 [key-value pairs] (2 * Similar to dict-pass parameters)
# #关于不定长参数: *args left **kwargs on the right
# #如果有其它参数: Put in front (priority)
54.return #结束函数, returns an object (each function has a return value if it is not defined by default to None (empty)) # #return多个对象, the interpreter converts these objects into a meta-ancestor as a whole end output.
Python common commands and underlying operators