Python Basics 3----sequence

Source: Internet
Author: User

Objective:

Sequence: List/tuple/string

Common elements of 3 sequences:

    • Each element can be indexed by an index
    • The default index value starts at 0 (negative numbers are also supported)
    • Can be sliced to get a collection of elements within a range
    • There are a lot of common operators (repeating operators, concatenation operators, Member relations operators)

Sequence common bif (built-in method)

1.list ([iterable])

The list () method is used to convert an iterative object into a list

The so-called iteration is the activity that repeats the feedback process in order to approach and achieve the desired goal or result.

Each repetition of a process is called an iteration, and the result of each iteration is used as the initial value for the next iteration.

Such as:

B=list ("ASDFG")

B

#结果: [' A ', ' S ', ' D ', ' F ', ' G ']

2.tuple ([iterable])

The tuple () method is used to convert an iterative object into a Narimoto group

3.str (obj)

Used to convert the Obj object to a string

4.len (sub)

Used to return the length of the sub parameter

5.max ()

Returns the maximum value in a sequence or parameter set, and the data type of a sequence or parameter to be consistent

6.min ()

Returns the minimum value in a sequence or parameter set, and the data type of the sequence or parameter to be consistent

7.sum (Iterable[,start])

Returns the sum of the series; start defaults to 0, set start to add from this value

8.sorted (Iterable,key=none,reverse=false)

Returns a sorted list (from small to large)

Consistent with the list's built-in method sort (), sort () is the implementation list in place, sorted () returns a sorted new list

9.reversed (Sequence)

Returns the value of the sequence in reverse order. returns an Iterator object

The difference between her and the list of built-in methods reverse () is the same as the difference between the above sorted ()

10.enumerate (iterable)

Generates an iterative object consisting of two tuples (a tuple of two elements), each of which consists of an index number of an iterative parameter and its corresponding element.

11.zip (iter1[,iter2[...])

Returns a tuple that is composed of various iterative parameters

======================================================================

Python Basics 3----sequence

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.