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