I. Basic data types
Integer: int
String: str (note: \ t equals a TAB key)
Boolean value: BOOL
Listing: List
list with []
Ganso: Tuple
For Ganso ()
Dictionary: Dict
Note: All data types exist in the class column that you want to correspond to, Ganso and list functions, the list can be modified, the meta-ancestor cannot be modified.
Two. Dictionary all data types:
Common operations:
Index, new, delete, key, value, key-value pair, loop, length
Class Dict (object): "" "Dict (), New Empty Dictionary dict (mapping), new dictionary initialized from a mapping Object ' s (key, value) pairs Dict (iterable), new dictionary initialized as if via:d = {} for K, V in Itera Ble:d[k] = v dict (**kwargs), new dictionary initialized with the name=value pairs in the keyword argument l Ist. For Example:dict (one=1, two=2) "" "Def Clear (self): # real signature unknown; Restored from __doc__ "" "D.clear () None. Remove all items from D. "" "Pass def Copy (self): # real signature unknown; Restored from __doc__ "" "D.copy ()-A shallow copy of D" "" Pass @staticmethod # known case def Fromkeys (*arg S, **kwargs): # Real signature Unknown "" "Returns a new dict with keys from iterable and values equal to value." " Pass Def get (self, k, d=none): # Real signature unknown; Restored from __doc__ "" "D.get (K[,d]) and D[k] if k in D, else D. D defaults to None." " Pass DEF items(self): # real signature unknown; Restored from __doc__ "" "D.items ()-a Set-like object providing a view on D's Items" "" Pass Def Keys (self): # Real Signature Unknown; Restored from __doc__ "" "D.keys ()-a Set-like object providing a view on D's Keys" "" Pass def pop (self, k, D =none): # Real signature unknown; Restored from __doc__ "" "D.pop (K[,d])-V, remove specified key and return the corresponding value. If key is not found, D is returned if given, otherwise keyerror is raised "" "Pass Def Popitem (self): # real Signat Ure unknown; Restored from __doc__ "" "D.popitem () (k, V), remove and return some (key, value) pair as a 2-tuple; But raise Keyerror if D is empty. "" "Pass Def SetDefault (self, k, d=none): # Real signature unknown; Restored from __doc__ "" "D.setdefault (K[,d])-D.get (K,d), also set D[k]=d if K not in D" "" Pass def update (s Elf, E=none, **f): # Known special case of Dict.update "" "D. Update ([E,]**f), None. Update D from Dict/iterable E and F. If E is present and have a. Keys () method, then Does:for k in e:d[k] = E[k] If e is present and lacks a. Keys () method , then does:for K, v-e:d[k] = V In either case, this is followed By:for k in f:d[k] = F[k] "" "Pass Def V Alues (self): # real signature unknown; Restored from __doc__ "" "D.values ()-an object providing a view on D's values" "" Pass Def __contains__ (self, *args, **kwargs): # Real signature Unknown "" "True if D has a key k, else False." " Pass Def __delitem__ (self, *args, **kwargs): # Real signature Unknown "" "Delete Self[key]." "" Pass Def __eq__ (self, *args, **kwargs): # Real signature Unknown "" "Return Self==value." "" Pass Def __getattribute__ (self, *args, **kwargs): # Real signature Unknown ' "" Return getattr (self, name). "" " Pass Def __getitem__ (self, y): # Real signature unknown; Restored from __doc__ "" "x.__getitem__ (y) <==&Gt X[y] "" "Pass Def __ge__ (self, *args, **kwargs): # Real signature Unknown" "" Return Self>=value. "" " Pass Def __gt__ (self, *args, **kwargs): # Real signature Unknown "" "Return Self>value." "" Pass Def __init__ (self, Seq=none, **kwargs): # Known special case of dict.__init__ "" "Dict ()-New empty Dicti Onary dict (mapping), new dictionary initialized from a mapping object ' s (key, value) pairs Dict (iterable) New dictionary initialized as if via:d = {} for K, V in iterable:d[k] = v dict (**kwargs) New dictionary initialized with the name=value pairs in the keyword argument list. For Example:dict (one=1, two=2) # (copied from class Doc) "" "Pass Def __iter__ (self, *args, **kwargs): # real S Ignature unknown "" "Implement iter (self)." "" Pass Def __len__ (self, *args, **kwargs): # Real signature Unknown ' "" "Return Len (self)." " Pass Def __le__ (self, *args, **kwargs): # Real SiGnature Unknown "" "Return Self<=value." "" " Pass Def __lt__ (self, *args, **kwargs): # Real signature Unknown "" "Return to Self
size of D in memory, in bytes "" "Pass __hash__ = None
Three. Examples of all dictionary data types
User_info = { 0: "Zhangyanlin", "age": "", 2: "Pythoner"} #获取所有的keyprint (User_info.keys ()) # Get all Valuesprint (User_info.values ()) #获取所有的key和valuesprint (User_info.items ()) Clear Erase All content user_info.clear () print (User_info) #get Gets the value based on key, if key does not exist, you can specify a default value val = User_info.get (' Age ') print (val) #update批量更新test = { ' a ': 111, ' B ': 222}user_info.update (test) print (User_info)
Four. Index
#如果没有key, Error user_info = { "name": ' Zhangyanlin ', "Age": " Job": ' Pythoner '}print (user_info[' name '])
Five. For loop
#循环user_info = { 0: ' Zhangyanlin ', ' age ': ' 2 ', ' pythoner '}for i in User_info: print (i) # Loop output all typed values for k,v in User_info.items (): print (k) print (v)
The above is the whole content of this article, I hope you can master the Python data structure to be helpful.