元素
添加到当前列表
中list.append(new_item)
new_item
:添加进列表的新的元素(成员)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': 'dewei'}
books.append(number)
books.append(tuple_test)
books.append(dict_test)
books.append('diango')
books.append(1)
books.append('')
books.append(True)
print(books)
print(id(books))
book_1 = ['西游记', '红楼梦']
book_2 = ['三国演义', '水浒传']
print(id(book_1))
book_1 = book_1 + book_2 # id改变
book_1 += book_2 # id不变
print(book_1)
print(id(book_1))