#元组
‘‘‘
Tuples are immutable lists and cannot be changed.
The same value as the list
‘‘‘
Tp= (a)
tp1= (' 127.0.0.1 ', ' 3307 ')
#元组只有count and index two methods.
lis=[' 127.0.0.1 ', ' 8080 ']
Tuple (LIS) #强制类型转换
#字典, legends are important.
#字典里的KYE不能重复
info={
' Name ': ' Xiaoming ',
' ID ': 1
}
Print (info[' name ']) #取不到值的时候会报错
Print (Info.get (' name ')) #取不到的时候报空
Print (Info.get (' Add ')) #取不到的时候报空
Print (Info.get (' Add ', ' Beijing ')) #取不到的时候就默认beijing
info[' Add ']= ' Shanghai ' #新增一个值
Info.setdefault (' pho ', 123333) #新增一个值
info[' id ']=4# Modify a value
Print (info)
#删除
Del info[' name ']
Info.pop (' Add ') #字典是无序的, so you must make a delete key when using pop
#info. Clear () #清空字典
Print (info)
new_info={
' Baobao ': {
' ID ': 1,
' Name ': ' Baobao ',
},
' Qiao ': {
' ID ': 1,
' Name ': ' Qiao ',
},
}
Print (new_info[' Baobao '].get (' name '))
New_info.get (' Baobao ') [' ID ']=new_info.get (' Qiao ') [' ID ']=7
Print (New_info.get (' Baobao '). Get (' id '))
Print (New_info.get (' Qiao '). Get (' id '))
#几个方法
Print (New_info.keys ())
Print (New_info.values ())
Print (New_info.items ())
#for循环写key和v
For k,v in Info.items ():
Print (K,V)
For J in Info:
Print (J,info.get (j)) #效率比第一个要高.
Python Basic Operations _ tuple _ dictionary operation