The examples in this article summarize the common operation methods of the list in Python for reference. The specific methods are as follows:
First, Python create a list:
Sample_list = [' A ', 1, (' A ', ' B ')]
Second, Python list operations:
Assume the following table:
Sample_list = [' A ', ' B ', 0,1,3]
1. Get one of the values in the list:
Value_start = sample_list[0]
end_value = sample_list[-1]
2. Deletes the first value of the list:
3. Insert a value in the list:
SAMPLE_LIST[0:0] = [' Sample value ']
4. Get the length of the list:
List_length = Len (sample_list)
5. List traversal:
For element in Sample_list:
print (Element)
Three, Python list advanced Operations/Tips
1. Generate a numeric increment list:
Num_inc_list = Range
#will return a list [0,1,2,..., 29]
2. Initialize the list with a fixed value:
Initial_value = 0
list_length = 5
sample_list = [Initial_value for i in Range (Ten)]
sample_list = [Initial_ Value]*list_length
# sample_list ==[0,0,0,0,0]
On this basis, readers can also continue to gather other ways of doing Python list operations to further consolidate and deepen their understanding of Python list operations.