Python common data Structures--list

Source: Internet
Author: User
Tags python list

1. List

Python has 6 built-in types of sequences, but the most common are lists and tuples.

The operations that a sequence can perform include indexing, slicing, adding, multiplying, and checking members.

In addition, Python has built-in methods for determining the length of the sequence and determining the maximum and bottom elements.

A list is the most common type of Python data that can appear as a comma-separated value within a square bracket.

The data items of the list do not need to have the same type.

Create a list by enclosing separate data items separated by commas in square brackets. As follows

List = [' AAA ', ' bbbb ', ' CCCC ']

List1 = [1,2,3,4,5]

List2 = ["A", "B", "C", "D"]

As with the index of a string, the list index starts at 0. Lists can be intercepted, combined, and so on.

Accessing values in a list

Use the subscript index to access the values in the list, and you can also use square brackets to intercept the characters as follows:

The result of the above example output:

Update list

You can modify or update the list's data items, or you can use the Append () method to add the list items as follows:

The result of the above example output:

To delete a list element

The result of the above example output:

python list script operators

As shown below:

python list interception

Python common data Structures--list

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.