Python container summary and python container Summary
Python container Summary
List
Variable Array
Tuple
Immutable Array
Dict
Dictionary of key-value pairs)
Initialization:
a={‘lyt':90}
Add:
a[‘zxw']=91
Access:
1. a [key]
Error if not found
2. a. get (key)
None returned if no data exists
3. a. get (key, val1)
The specified val1 is not returned.
#### Judgment:
>>>key in aTrue/False
Delete:
a.pop(key)
There is a corresponding val returned, and no error is reported
Note that the key must be a non-variable, such as a string, integer, or tuples. Cannot be an array.
>>> a[1, 2, 3]>>> b(1, 2)>>> d{'lyt': 90}>>> d[a]=99Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: unhashable type: 'list'>>> d[b]=99>>> d{(1, 2): 99, 'lyt': 90}
Set
Set Without Duplicate keys
Create
A list is required.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!