Python container summary and python container Summary

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.