Python sequence type

Source: Internet
Author: User

Sequence Types:

(1) sequence type: mainly including strings, lists, and metadata.

* The members are ordered, and one or more members can be accessed through the subscript offset.


(2) sequence type operators:

* Member relationship operators (in and not in): used to determine whether an element belongs to a sequence.

* Join operator (+): concatenates a sequence with another sequence of the same type.

* Repeated operator (*): Copies a sequence multiple times. Format: sequence * copies_int.

* Slice operator ([], [:], [:]): The index can be a positive value (0 <= index <= len (sequence)-1 ), you can also use a negative index (-len (sequence) <= index <=-1 ).

Format 1: sequence [index].

Format 2: sequence [start: end].

Format 3: sequence [start: end: Number of intervals].

Supplement: the index value is optional. If None is not provided or used as the index value, the slice operation starts from the beginning of the sequence or ends at the end of the sequence.


(3) built-in functions:

* Type conversion:

List (): converts an Iterated object to a list.

Tuple (): converts an iteratable object into a tuples.

Str (): converts an object to a string.


* Operable built-in functions:

Len (): returns the length of an object. This object can be sequence (string, list, and metadata) or mapping (dictionary ).

Sum ()

Reversed ()


Two strings:

List 3:

Tuples:




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.