Python Xiaobai Growth Diary day 1 2.25 11; 09

The use of the list:


name=['1','2','3','4','5'] 


print(name[0],name[2])


Note that the list should be used in [], divided into


print 1 3; if it is [-1] print 5; if it is [1:3] print out ['2' ,'3'] (regardless of the head and tail) (slice);


if it is [-1:-3] The wrong output is [] The reason direction must be correct from left to right [-3:-1] Printing out ['3', '4'] also follows the principle of disregarding the head and the tail;


if you want to print out ['4' ,'5'] cannot write [-2:0] to write [-2:];


but [0:2]=[:2] The output results are all ['1', '2'];


name.append ('6')-->['1','2','3','4','5','6']; Add the last digit    


name.insert(2,'2.5')-- >['1','2','2.5','3','4','5']; insert 2.5 in the third place


name[2]=('2.5')-->['1', '2', '2.5', '4', '5'] ; replace the third digit with 2.5


name.remove('2')-->['1','3','4',' 5']: delete the '2' inside


name.pop(1)==del name[1]-->['1','3','4','5']; delete position 1






name=[ '1','2','3','4','5'] print (name) print(name.index('3'))


output ['1', '2', '3', ' 4', '5']


           2


print(name.index('3')) means to find the position of '3'






name=['1','2','3','4','5'] print (name) print( name.index('3')) print(name[name.index('3')]) output ['1', '2', '3', '4', '5'] 
           2 


           3


print(name The meaning of [name.index('3')]) is easy to understand compared to the above


name=['1','2','3','3','4','5'] print(name.count ('3'))


The output is 2, which means that the printed '3' has several


name=['1','2','3','3','4','5'] name.clear () print(name.count('3'))name.clear() means to clear all the arrays 


name=['1','2','3','3','4','5 '] name. reverse() print(name)


['5', '4', '3', '3', '2', '1'] 


name.reverse() means to reverse the sequence




name=['1',' 3','2','3','4','5'] name.sort() print(name)['1', '2', '3', '3', '4', ' 5'] 


name.sort() sorts the sequence, the general order is # alphanumeric (actually according to ASCII code)


name=['1','3','2','3','4','5'] name2=(1,2,3,4) name.extend(name2) print(name)


[' 1', '3', '2', '3', '4', '5', 1, 2, 3, 4]


The awareness of name.extend(name2) is to add the sequence of name2 to name.


Be aware The meaning of the words used in the above sentences is extended and expanded

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325818117&siteId=291194637