The sequence of Python reading notes

Source: Internet
Author: User

Sequence sequence

A sequence is a set of sequential elements

There are two types of sequences: tuple (fixed value table; also translated as tuple) and List (table)

>>>S1 = (2, 1.3, ' love ', 5.6, 9,, False) # S1 is a tuple

>>>S2 = [True, 5, ' smile '] # s2 is a list

The main difference between a tuple and a list is that once established,each element of a tuple cannot be changed, and the elements of the list can be changed again.

References to elements

The subscript of the sequence element starts with 0

Other reference methods

Range Reference: Basic style [lower limit: Upper limit: Step length]

As can be seen from the above, the upper limit is not included in the range reference when the upper limit is indicated .

Trailing element reference

>>>print S1[-1] # The last element of a sequence

>>>print S1[-3] # third element of sequence countdown

Similarly, if s1[0:-1], then the last element will not be referenced (again, excluding the upper bound element itself)

string is a tuple

strings are a special element, so you can perform related operations on tuples.

>>>str = ' abcdef '

>>>print Str[2:4]

The sequence of Python reading notes

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.