Python Review and Collation 4: Sequence (string/list/tuple)

Source: Internet
Author: User

0. Description


A sequence is a generic term for some of the data types of python, such as strings, lists, and tuples, which are collectively referred to as sequences because their members are arranged in an orderly manner and can be accessed by the subscript offset to one or more of its members .

The idea is to first introduce the operators and the built-in functions that apply to all sequence types, and then describe each of these sequence types separately .



1. Sequence


Sequence types have the same access pattern: Each of its elements can be obtained by specifying an offset, and multiple elements are obtained by slicing the operation . In the python sequence, the rules for offsets are as follows (assuming the sequence length is N):

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7D/92/wKiom1bq3yyQV70pAAAP0Jc09p0317.png "title=" Drawing-blogs using the. png "alt=" Wkiom1bq3yyqv70paaap0jc09p0317.png "/>


(1) Standard type operator

The standard type operators are described in the Python review and Collation 2:python objects, which are generally applicable to all sequence types.


(2) Sequence type operator

The following are presented separately:

    • Member relationship operator: In,not in

for a string, it is to determine whether the character is in the string (in fact, this character is also a string object), for lists and tuples, is to determine whether the object belongs to the sequence of objects, for example, as follows:

>>> myList = [' xpleaf ', ' leaf ', ' cl ']>>> ' xpleaf ' in mylisttrue>>> ' cl ' not in Mylistfalse

    • Connection operator: +

    • Repeat Operator: *

    • Slice operator: [],[:],[::]

    • Slice operation extension: Using the step index

    • More on the slice index














This article is from the "fragrant fluttering leaves" blog, please make sure to keep this source http://xpleaf.blog.51cto.com/9315560/1752376

Python Review and Collation 4: Sequence (string/list/tuple)

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.