2019605-- usage differences extend the function and append function

1, use append function

. 1 list1 = [91 is, 95, 97, 99 ]
 2 list2 = [92, 93, 96, 98 ]
 . 3  list1.append (list2)
 . 4  # added to list list1 list2 list 
. 5  Print (list1)
 . 6  
. 7  
. 8 > >> [91 is, 95, 97, 99, [92, 93, 96, 98 ]]
 . 9  
10 the append function usage

2, extend the use of the function

. 1 list1 = [91 is, 95, 97, 99 ]
 2 list2 = [92, 93, 96, 98 ]
 . 3  list1.extend (list2)
 . 4  # Add the contents of list1 list2 list to the list 
. 5  Print (list1)
 . 6  
. 7 >>> [91 is, 95, 97, 99, 92, 93, 96, 98 ]
 . 8  
. 9 Extend function usage

 

Guess you like

Origin www.cnblogs.com/yssshiny/p/10980018.html