<>目录
* append的功能
* append的用法
* append的注意事项
<>append的功能
* 将一个元素添加到当前列表中
<>append的用法
* 用法:list.append(new_item)
* 参数:new_item:添加进列表的新的元素(成员) In [19]: names = ['insane'] In [20]:
names.append('loafer') In [21]: print(names) ['insane', 'loafer']
<>append的注意事项
* 被添加的元素只会被添加到末尾变量
* append函数是在原有列表的基础上添加,不需要额外添加新的变量
<>实战
* 每次只能添加一个变量 # coding:utf-8 books = [] print(id(books)) books.append('python')
print(books) print(id(books)) number = 1.1 tuple_test = (1,) dict_test = {'name'
: 'insane'} books.append(number) # 每次只能加入一个变量 books.append(tuple_test) books.
append(dict_test) print(books) books.append('django') books.append(1) print(
books) print(id(books)) 2029563540224 ['python'] 2029563540224 ['python', 1.1,
(1,), {'name': 'insane'}] ['python', 1.1, (1,), {'name': 'insane'}, 'django',
1] 2029563540224 Process finished with exit code 0