clear 方法
clear() 函数用于清空列表,类似于del a[:]。
clear()方法语法:list.clear()
list1 = ['Google', 'Runoob', 'Taobao', 'Baidu']
print("列表清空前 : ", list1)
list1.clear()
print("列表清空后 : ", list1)
#控制台
#列表清空前 : ['Google', 'Runoob', 'Taobao', 'Baidu']
#列表清空后 : []
append的方法
append() 方法用于在列表末尾添加新的对象。
append()方法语法: list.append(obj)
list1 = [123, 'xyz', 'zara', 'abc']
list1.append( 2009 )
print("Updated List : ", list1)
#控制台
#Updated List : [123, 'xyz', 'zara', 'abc', 2009]