Python basic notes-sequence of data types (0)

Source: Internet
Author: User

First, the definition

Members are ordered, and can be accessed by the subscript offset to one or several of its members, which are collectively known as sequences (sequence)

The sequence consists mainly of the following types: string (str and Unicode), list, tuple (tuple)

Second, sequence-related operators

In and not--member operator: used to determine whether an element belongs to a sequence obj [not] in sequence

+-connect operator: Connect a sequence with another sequence of the same type Sequence1 + Sequence2

*-and repeat operators: Copy multiple copies of a sequence sequence * copies_int

[] [:] [::]--slice operator: Obtain a data element by specifying the subscript, or by specifying the subscript range to obtain a set of elements of a sequence sequence[s_index:e_index:step]

R/R----meta-character operators:

U/u-to-Unicode string operators:

Three, built-in functions

List (ITER) converts an iterative object to a table

STR (obj) converts the Obj object to a string (the string representation of the object)

Unicode (obj) converts an object to a Unicode string (using the default encoding)

The basestring () abstract factory function, which simply provides the parent class for STR and Unicode functions, cannot be instantiated or called

Tuple (ITER) an iterative object is converted into a tuple object

  Built-in functions for sequences

  Enumerate (ITER) takes an iterative object as a parameter, returning a enumerate object (also an iterator) that generates a tuple of index and item values for each element of ITER

Len (SEQ) returns the length of the SEQ

Reversed (seq) takes a sequence as a parameter, returning an iterator that is accessed in reverse order

Sorted (Iter,func=none,key=none,reverse=false) takes an iterative object as an argument, returns an ordered list, and the optional parameter Func,key and reverse have the same meaning as the list.sort () .
SUM (seq, init=0) returns the sum of the SEQ and optional parameter init, which has the same effect as reduce (operator.add,seq,init)

Zip ([it0, It1,... ItN]) returns a list whose first element is It0,it1,... The first element of these elements consists of a tuple, and the second one ... And so on

Max (Iter,key=none) or MAX (Arg0,arg1...,key=none) returns to Iter or (Arg0,arg1,...) The maximum value in the, if key is specified, the key must be a callback function that can be passed to the sort () method for comparison.

Min (iter, Key=none) or min (arg0, arg1....,key=none) returns the minimum value inside ITER, or returns (Arg0,arg2,...) The minimum value inside, if you specify key, the key must be a callback function that can be passed to the sort () method for comparison.

  

  

  

Python basic notes-sequence of data types (0)

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.