Want to write something to the process of learning Python to record, so there is a rookie learn python ...
List lists are often used in writing programs, and are data structures used to process a set of ordered items.
For example, range (1,5) is actually a list of integers
So
For x in range (1,5)
can be written
For x in [1,2,3,4]
Here are some common basic operations for lists
Create a list of empty lists first
list = []
Add a value to this list with append
List.append (1) #向list里面添加1
You can add multiple values to the middle of a list by extend
List.extend ([2,3,4,5,6]) #向list中一次性添加2, 3,4,5,6
You can remove a known value from the list by removing
List.remove (6) #将list中的6删除
If I want to access a value in the list, I need to know his location, and the values in the list have an attribute that can be understood as the position number, starting with 0
For example, in the list I want to know what the 2nd value is, just need
LIST[1]
Known location, you can also modify the value to modify the first value in the list to ' Frist '
List[0] = ' frist '
can be removed to remove the frist that was just inserted
Del List[0]
Can insert data, insert ' 0 ' in the first position
List.insert (0, ' 0 ')
If you only know what the value is, you need index ()
List.index (3) List.index (4)
Beginners Learn python (one) list basic operations