A list of python basics and python Basics
The list function converts other types of sequences to a list, as shown in figure
>>> List ("hello world ")
['H', 'E', 'l', 'l', 'O', '', 'w', 'O', 'R', 'l ', 'D']
Element assignment can change the list, as shown in figure
>>> Sen
['H', 'E', 'l', 'l', 'O', '', 'w', 'O', 'R', 'l ', 'D']
>>> Sen [0] = 'H'
>>> Sen
['H', 'E', 'l', 'l', 'O', '', 'w', 'O', 'R', 'l ', 'D']
Use del to delete elements from the list, as shown in figure
>>> Sen
['H', 'E', 'l', 'l', 'O', '', 'w', 'O', 'R', 'l ', 'D']
>>> Del sen [0]
>>> Sen
['E', 'l', 'l', 'O', '','', 'w', 'O', 'R', 'l', 'D']
You can assign values to multiple elements at a time, as shown in figure
>>> Sen
['E', 'l', 'l', 'O', '','', 'w', 'O', 'R', 'l', 'D']
>>> Sen [: 3] = list ("hhhh ")
>>> Sen
['H', 'h', 'O', '', 'w', 'O', 'R', 'l ', 'D']
You can insert a sequence into the multipart assignment, as shown in figure
>>> Sen = list ("world ")
>>> Sen [0: 0] = list ("hello ")
>>> Sen
['H', 'E', 'l', 'l', 'O', '', 'w', 'O', 'R', 'l ', 'D']
Append -- append a new object to the end of the list and directly modify the original list.
Count -- count the number of times an element appears in the list
Extend -- append multiple values of another sequence at the end of the list to directly modify the original list.
>>> Sen = list ("world ")
>>> Sen. extend (list ('er '))
>>> Sen
['W', 'O', 'R', 'l', 'D', 'E', 'R']
Index -- locate the index location of the first matching item of a value from the list
>>> Sen
['W', 'O', 'R', 'l', 'D', 'E', 'R']
>>> Sen. index ('R ')
2
Insert -- insert an object to the list
Pop -- remove an element from the list (the last one by default) and return the value of this element.
>>> Sen
['W', 'O', 'R', 'l', 'D', 'E', 'R']
>>> Sen. pop ()
'R'
>>> Sen
['W', 'O', 'R', 'l', 'D', 'E']
>>> Sen. pop (0)
'W'
NameError: name 'seb' is not defined
>>> Sen
['O', 'R', 'l', 'D', 'E']
Remove -- remove the first match of a value in the list
>>> Sen
['O', 'R', 'l', 'D', 'E']
>>> Sen. remove ('l ')
>>> Sen
['O', 'R', 'D', 'E']
Reverse -- store the elements in the list
Sort -- sort the list in the original position and return a null value
Sorted -- get a copy of the sorted list. This function is used for any sequence.
>>> Sen_sorted = sorted (sen)
>>> Sen_sorted
['D', 'E', 'O', 'R']
>>> Sen
['O', 'R', 'D', 'E']