List Operation Method summary in Python, pythonlist
The examples in this article summarize the common operations on the list in Python for your reference. The specific method is as follows:
I. Python creation list:
sample_list = ['a',1,('a','b')]
Ii. Python list operations:
Suppose there is a list as follows:
sample_list = ['a','b',0,1,3]
1. Get a value in the list:
value_start = sample_list[0]end_value = sample_list[-1]
2. Delete the first value of the list:
del sample_list[0]
3. Insert a value to 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)
Iii. Python list Advanced Operations/skills
1. generate a list of incremental values:
num_inc_list = range(30)#will return a list [0,1,2,...,29]
2. initialize the list with a fixed value:
initial_value = 0list_length = 5sample_list = [ initial_value for i in range(10)]sample_list = [initial_value]*list_length# sample_list ==[0,0,0,0,0]
On this basis, readers can continue to collect other methods for Python list operations to further consolidate and deepen their understanding of Python list operations.
Python list operations
Direct:
New_list = [I for I in a_list if I> 0]
New_list is a number greater than 0.
Python list Operation
Let me answer.
For index in range (len (list )):
List [index] = int (10 * list [index])
Print list
# Now you can see your satisfactory results. I tried it. No problem.