This article mainly introduces relevant information about python container summary and arrangement. Friends in need can refer to
python container summary and arrangement
list
Variable array
tuple
Immutable array
dict
Dictionary of key-value pairs
Initialization:
a={‘lyt':90}
Add:
a[‘zxw']=91
Access:
1.a [key]
If it does not exist, an error will occur.
2.a.get(key)
Does not exist and returns None
3.a.get(key,val1)
Does not exist and returns the specified val1
>>>key in a True/False
a.pop(key)
>>> a [1, 2, 3] >>> b (1, 2) >>> d {'lyt': 90} >>> d[a]=99 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list' >>> d[b]=99 >>> d {(1, 2): 99, 'lyt': 90}
The above is the detailed content of Share a summary of python containers. For more information, please follow other related articles on the PHP Chinese website!