Sequence is the most basic data structure in Python. Each element in the sequence is assigned a number-its position, or index, the first index is 0, the second index is 1, and so on.
Python has 6 built-in types for sequences, but the most common are lists and tuples.
Operations that can be performed on sequences include indexing, slicing, adding, multiplying, and checking members.
In addition, Python has built-in methods for determining the length of the sequence and determining the largest and smallest elements.
list1 =['physics','chemistry',1997,2000]
list2 =[1,2,3,4,5]
list3 =["a","b","c","d"]
Like the index of a string, the list index starts at 0. The list can be intercepted, combined, etc.
How to update the list in python?
aList =[123,'abc',4.56,['inner','list'],(7-9j)]
print aList[2]
aList[2]='float replacer'
print aList
aList.append("hi, i'm new here")
print aList
The results are as follows:
4.56[123,' abc','float replacer',['inner','list'],(7-9j)][123,'abc','float replacer',['inner','list'],(7-9j),"hi, i'm new here"]
Content supplement:
Python list (List)
Sequence is the most basic data structure in Python. Each element in the sequence is assigned a number-its position, or index, the first index is 0, the second index is 1, and so on.
Python has 6 built-in types for sequences, but the most common are lists and tuples.
Operations that can be performed on sequences include indexing, slicing, adding, multiplying, and checking members.
In addition, Python has built-in methods for determining the length of the sequence and determining the largest and smallest elements.
The list is the most commonly used Python data type, and it can appear as a comma separated value in square brackets.
The data items of the list need not have the same type
To create a list, simply enclose the different data items separated by commas in square brackets. As follows:
list1 =['physics','chemistry',1997,2000]
list2 =[1,2,3,4,5]
list3 =["a","b","c","d"]
Like the index of a string, the list index starts at 0. The list can be intercepted, combined, etc.
The above is the details of how to update the value of the Python list. For more information about the method of updating the value of the Python list, please follow ZaLou.Cn
Recommended Posts