Types and data structures in Python

Source: Internet
Author: User

I. Data type

There are six standard data types in Python:

    • Number (numeric)
    • String (String)
    • List (lists)
    • Tuple (tuple)
    • Sets (collection)
    • Dictionary (dictionary)

In addition to the list and dictionary dictionaries, the data types are immutable data types.

Two. Data structure

Common data structures in Python can be collectively referred to as Containers (container). sequences (such as lists and tuples), mappings (such as dictionaries), and collections (set) are the three main types of containers.

    • List: Shoplist = [' Apple ', ' mango ', ' carrot ', ' banana ']
    • Tuple: Tu = (123,456, ' hello ')
    • Dictionary: di = {' A ': 123, ' B ': ' Something '}
    • Collection: Fruitset = {' Apple ', ' pear ', ' apple '}

1. Lists and tuples

1 # 1. List with [], tuple with () 2 # 2. The contents of the list are variable, the tuple content is not mutable, but can be added in nested form 3 # 3. Nested lists within a tuple
4 # 4. Add "comma" when defining Ganso with only one element to avoid ambiguity with mathematical operations
5 # 5. Tuples typically have different data types, and lists are the same type of data queue. A tuple represents a struct, whereas a list represents a sequence
6 # 6. The list cannot be used as a dictionary key, and tuples can

Types and data structures in Python

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.