Difference in python append, extend, and insert the

= a_list [X for X in Range (. 1,. 11 )]
 Print (a_list) 
a_list.append ( ' sdadfewf ' )   # entire string into the final list 
Print (a_list)
 # [. 1, 2,. 3,. 4, . 5,. 6,. 7,. 8,. 9, 10, 'sdadfewf'] 

B_LIST = [X for X in Range (. 1,. 11 )]
 Print (B_LIST) 
b_list.extend ( ' sdadfewf ' )   # string each the last element of the list into the 
Print (B_LIST)
 # [. 1, 2,. 3,. 4,. 5,. 6,. 7,. 8,. 9, 10, 'S', 'D', 'a', 'D', 'F ',' e ','w', 'f']

c_list = [X for X in Range (. 1,. 11 )]
 Print (c_list) 
c_list.insert ( 3, ' sdadfewf ' )   # entire string into the list an index of 3 
Print (c_list)
 # [. 1, 2 , 3, 'sdadfewf', 4 , 5, 6, 7, 8, 9, 10]

 

Guess you like

Origin www.cnblogs.com/yang901112/p/11311793.html