python container summary


python container summary

list

An array variable

tuple

Immutable array

dict

Dictionary of key-value pairs (key-value) (dictionary)

Initialization:

a={ ' lyt':90}

Add:

a[ ' zxw']=91

Access:

1.a[key]

Nothing can go wrong

2.a.get(key)

There is no return None

3.a.get(key,val1)

Does not exist to return the specified val1

# # # # :

>>>key in a
True/False

Delete:

a.pop(key)

The corresponding val is returned and no error is reported

Note that key must be immutable variables such as strings, integers, and tuples. 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

Does not contain a collection of duplicate key

create

One list needs to be provided

Thank you for reading, I hope to help you, thank you for your support of this site!