Python common data structure __ data structure

Source: Internet
Author: User

The 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. First, sequence (list, tuple, and string)

Each element in the sequence has its own number. There are 6 types of built-in sequences in Python. where lists and tuples are the most common types. Other include strings, Unicode strings, buffer objects, and Xrange objects. The following tables, tuples, and strings are highlighted below. 1, List

The list is variable, which is the most important feature that distinguishes it from strings and tuples: The list can be modified and the strings and tuples cannot. (1), create

You can create a list in the following ways:

1 2 3 4 List1 = [' Hello ', ' world '] print list1 list2 = [1, 2, 3] Print List2

Output:
[' Hello ', ' world ']
[1, 2, 3]

As you can see, this is created in a way that is very similar to an array in JavaScript.

(2), List function

The list function (in fact the list is a type rather than a function) is useful for creating lists of strings:

1 2 LIST3 = List ("Hello") print List3

Output:

[' H ', ' e ', ' l ', ' l ',

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.