前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python 列表的extend函数

Python 列表的extend函数

作者头像
Zkeq
发布2022-05-18 13:39:25
7150
发布2022-05-18 13:39:25
举报
文章被收录于专栏:ZkeqZkeq

列表的extend函数

功能
  • 将其他列表元组中的元素导入当前列表
用法
  • list.extend(iterable)
参数
  • iterable代表列表或元组 , 该函数无返回值
注意事项
  • 传入的必须是iterable
  • 直接传入字符串的话会被拆分成很多个单个字符
  • 不可传入整形或者布尔类型之类的(不是iterable就不行)
  • 传入字典的话只会保留key的值
代码
代码语言:javascript
复制
# 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)

test = []
# test.extend('abcd')
test.extend({'name': 'dewei', 'age': 33})
# test.extend(True)
print(test)
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-10-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 列表的extend函数
    • 功能
      • 用法
        • 参数
          • 注意事项
            • 代码
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档