1. Data structure
A data structure is a collection of information that is organized in some way. The most basic data structure is the sequence .
2. Sequence
The types commonly used in a sequence are the following six classes: list, tuple, string, Unicode string, buffer object, Xrange object.
3. List
(1) What is a list?
Lists are made up of numbers, strings, etc., and can be modified arbitrarily.
A = [' samp ', ' eggs ', 520, 100, 34]
(2) Operation of the list
A. Index
The elements of the list have a specific location, which is described by the index.
An element can be found through an index.
Indexes are divided into positive and negative indexes. The positive index is from left to right, the first position is 0, the negative index is from right to left, and the first position is-1.
A[3] = 100
A[-3] = 520
B. Shards
Shards can find and manipulate elements within a range. For specific shards, see python-string.
A[0:3] = [' samp ', ' eggs ', 520]
A[-1:-3] = [520, 100]
Note: The number on the left side of the slice is smaller than the right, or empty if it is greater.
The step size of the Shard, the default step is 1, and if the step is set to N (n>1), the n-1 elements are separated from each other. The step size can also be negative, indicating that the element is extracted from left to right.
Example: Numbers = [1,2,3,4,5,6,7,8,9,10]
Numbers[0:10:2] = [1,3,5,7,9]--The last 2 indicates a step size of 2
C. Add
The two identical sequences can be added between each other.
D. Multiply
With the number n list will wait for a new list, the new list is the original list loop n times.
The multiply operation can be used to initialize the. None is an internal key value in Python, and you can use none to indicate that the elements in the list are empty.
A = [none]*10--Initializes a list of length 10
E. Judging membership
Use the in operator to determine whether a value is in a sequence. In is a Boolean operator that returns true if it is in a sequence, otherwise false.
F. Iteration
Follow-up learning ...
4. Tuples
python-Data Structure-list