Python basic data structure sequence, six types of built-in sequence: List tuple string Unicode string Buff object and Xrange object
Sequence common operations:
Index: The number of the element is from 0 to the index number is negative when the lookup method is right-to-left index written in []
Sharding: An index-like operation can specify a range, which can be created in the form of B = a[:] When creating a copy of an object, so that when a is manipulated it does not affect B because they are not pointing to the same area
Add: Indicates the connection operation, the list after the connection is a new list can not change the original structure of the list, the sequence is added to the same type, otherwise it will be reported Tpyeerror
Multiplication: Indicates continuous output of several objects
Check whether the element is a member: Check that the elements are in the sequence with the keyword in
Length: Check the length of the sequence with Len (a) #a为序列
Max element: Check the largest element in the return sequence with Max (a)
Minimum element: Check the smallest element in the return sequence with min (a)
Python lists and tuples
List: Modifiable sequences such as a=[1,2,3,4] can be indexed to modify the element
Tuples: Non-modifiable sequences that cannot be modified if the elements in the tuple are defined. As a = (1,2,3,4) It is important to note that if there is only one element in the tuple, a comma is added, such as a = (1,)
# because tuples and string definitions cannot be modified, Python provides a list function to convert them to lists such as a = List (b) # B is a tuple or string
The # del keyword is used to delete a sequence of elements or, defined variables
Basic operation of the list:
Append: Adding an object at the end of a sequence, such as a =[1,2];b=[3,4];a.append (b) operation, the result of entering a is [1,2,[3,4]] B is an element in a
Extend: Appending an object and append at the end of a sequence is different when the value of a is [1,2,3,4] after performing the above operation
Appending the elements in B to a in a has a number of elements of 4.
Reverse: Reverse Sequence Storage
Sort: The default for a sequence is ascending if you want the descending sort to be in sequence. Sort (reverse =true)
######### #以上操作, can change the original structure of the sequence, but there is no return value this to remember ##################
Count: Checks the number of occurrences of an element in a sequence if A.count (b) #b to an element
Index: Checks the first occurrence of an element in a sequence
Tuple: is a method of converting a sequence into a narimoto group
Python basic data structure sequence