Python Common data structures

Source: Internet
Author: User

There are four most commonly used data structures in Python, namely list, dictionary (dict), set (set), and tuple (tuple)

Below is a brief description of their differences and connections

1. Initialization

It has to be said that Python data structures are much simpler to initialize than Java.

List=[]

dict={}

Tuple= (1, 2,)

Set= ([i])

After initialization, the print set result is: {dict}, it can be found that the set is not the value of the

2. Is it orderly

List and tuple are ordered, dict and set are unordered

3. Whether variable

Once a tuple is initialized, it can be accessed as a list by subscript, but cannot be changed, and List/dict/set are mutable.

The set is variable and can be deleted by adding (), remove (), or the intersection of two sets, and the operation of a set

4. Can I have duplicate elements

List,tuple can have

Set can not have duplicate elements

The value of dict can be repeated, but key cannot be

Python Common data structures

Related Article

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.