Home > Article > Backend Development > Share a summary of python containers
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/FalseDelete :
a.pop(key)There is a corresponding val returned, and no error is reportedNote that the key must be an immutable variable, such as a string, an integer, or a tuple. Not an array.
>>> 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}set A collection without duplicate keysTo create you need to provide a list###
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!