'''
extend功能
将其他列表或元组中的元素,导入到当前列表中
extend用法
list.extend(iterable)
参数:
iterate代表列表或元组,该函数无返回值
studens = ['dawei','xiaomu','xiaogang']
new_students = ('xiaowang','xiaogang')
students,extend(new_students)
print(students)
'''
# coding:utf-8
manhua = []
history = []
code = []
new_manhua = ('a','b','c')
new_history = ('中国历史','日本历史','韩国历史')
new_code = ('python','django','flask')
manhua.extend(new_manhua)
history.extend(new_history)
code.extend(new_code)
print(manhua,history,code)
history.extend(manhua)
del manhua
print(history)
# coding:utf-8
list1 = [1,3,7,9]
list2 = [2,2,6,7]
new_list = []
new_list.extend(list1)
new_list.extend(list2)
new_list.sort()
print(new_list)
python-列表的extend函数
最新推荐文章于 2024-07-20 11:35:49 发布
本文介绍了Python中list.extend()函数的使用方法,展示了如何将其他列表或元组的元素追加到现有列表,并通过实例演示了manhua、history和code列表的更新过程。同时讲解了如何合并多个列表并进行排序。
摘要由CSDN通过智能技术生成