Python List append() Method

append( ) 方法是將一個元素 (element) 追加到清單最後。

例一:

students =[”小明”, “利香”, “若蘭”]

students.append (“甘仔”)

print (students)

 顯示:

[”小明”, “利香”, “若蘭”, “甘仔”]

例二:

squares = [

for i in range (10):

       squares.append (i**2)

print (squares)

 顯示:

[0, 1 , 4, 9, 16, 25, 36, 49, 64, 81]

Share your thoughts