python-列表的extend函数

本文介绍了Python中list.extend()函数的使用方法,展示了如何将其他列表或元组的元素追加到现有列表,并通过实例演示了manhua、history和code列表的更新过程。同时讲解了如何合并多个列表并进行排序。
摘要由CSDN通过智能技术生成
'''
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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值