1,int #数字 (plastic)
A=1
Print (Type (a)) # # #结果 <class ' int ' >
2,bool #布尔值True与False
Non-0 is true, non-null is True
Print (bool (9))
True
3,str #字符串
Single and double quotes are the result of Str.
A= "123"
Print (Type (a))
<class ' str ' >
# #字符串的格式化输出
Format # #格式化输出的另一种方式
A= "Hello World {Name}"
Print (A.format (name= "format"))
Hello World format
# #字符串拼接
A= ' SQW '
b= ' AAAAAAA '
Print (A+B)
4,tupe (#元祖) tuple #元祖不可改变
Enclosed in parentheses is Ganso (Ganso is immutable)
A= (' 1 ', ' a ')
Print (Type (a))
<class ' tuple ' >
# # #元祖删查操作 (Yuan zu cannot be changed)
# #查
T1= (' A ', ' 1 ', ' qeqw ', 12)
Print (t1[2]) # # #' Qeqw '
# #删
del T1
5,list[1,2,3, ' abc '] #列表 list
A=[' A ', ' wqe ', 1]
Check
Index (subscript), all starting from 0
Slice
Count check occurrences of an element
Index to find its corresponding location according to the content
Increase
Append () Append
Insert (Index, "content")
Extend extension
Modify
A[index] = "New Value"
A[start:end] = [A,b,c]
Delete
Remove ("content")
Pop (index)
Del A, Del A[index]
Clear () Clear
6,dict{' name ': ' Alex '} #字典 dict
dic={' name ': ' Alex '}
dic1={}
Dic2=dict ((' Name ', ' Alex '),)
Print (DIC2)
Dic3=dict ([[' Name ', ' Alex '],])
Print (DIC3)
dic1={' name ': ' Alex '}
dic1[' age ']=18
Print (DIC1)
# #增
dic1["Zen"]=12
Key exists, does not change, returns the value corresponding to the corresponding key in the dictionary
Ret=dic1.setdefault (' age ', 34)
Print (ret)
Key does not exist, adds a new key-value pair in the dictionary, and returns the corresponding value
Ret2=dic1.setdefault (' Hobby ', ' girl ')
Print (DIC1)
Print (Ret2)
# #删
Dle Dic1 # #删除字典
Dle dic["Zen"] #删除这对键值
Dic3=dic1.fromkeys (["A", "B", "C"], "AAA") # #a, the value of the B,c key is "AAA" (same as List) if you change a value, the other value will change
Print (DIC3)
#查 by Key to find
dic3={' age ': ' Name ': ' Alex ', ' hobby ': ' Girl '}
Print (dic3[' name '])
Print (List (Dic3.keys ())) # # Keys
Print (List (dic3.values ())) # # values Value
Print (list (dic3.items)) # # Items take out all key-value pairs
dic3={' age ': ' Name ': ' Alex ', ' hobby ': ' Girl '}
dic3[' age ']=55
Print (DIC3)
# # #get (return value with key, none returned)
d={"name": "Zhangbin", "Age": "23"}
Print (D.get ("name")) Result # #zhangbin
Print (D.get ("sex")) result # #None
Print (D.get ("Sex", "male")) result # #male
# #update修改
dic4={' age ': ' Name ': ' Alex ', ' hobby ': ' Girl '}
dic5={' 1 ': ' 111 ', ' 2 ': ' 222 '}
dic5={' 1 ': ' 111 ', ' name ': ' 222 '}
Dic4.update (DIC5) #在dic4中添加dic5字典的类容 (do not modify DIC5) if you have the same key to overwrite
Print (DIC4)
Print (DIC5)
Python Basic data type