Lists,tuples and sets of Python

Source: Internet
Author: User

Lists List

A list is an ordered sequence (collection) that can be understood as an array type in other languages, but the list is more flexible and powerful.

The list is defined by square brackets [], and its elements can be any type or object, and a list can contain mixed elements.

Cases:

x = [] Create empty list

x = [1, 2] x = [' A ', ' B '] x = [[[1, 2]] x = [{1, 2}] creates a list whose elements are of any type or object

x = [1, ' AB ', [1, 2], {1, 2},{1:1, 2:2}] Create list with mixed elements in a list

List access can be accessed through a slice or index, and the index value starts at 0, and unlike other language data, the list index can be negative, and 1 represents the last element.

x = [' A ', ' B ', ' C ']

x = [ A ' B ' C ]
Positive index 0 1 2
Negative index -3 -2 -1

Lists,tuples and sets of Python

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.