• 技术文章 >Python技术 >Python基础教程

    python使用insert添加列表元素

    小妮浅浅小妮浅浅2021-08-25 09:20:08原创2965

    说明

    1、index表示指定位置的索引值,insert()将p_object插入listname列表第index要素的位置。

    2、如果要添加的是序列,则insert()将该序列作为整体插入列表的指定位置。

    语法

    listname.insert(index, p_object)

    实例

    name_list = ['大伟', '小伟', '小小伟']
    name_list.insert(1, 'Jack')
    print(name_list)
    name_list.insert(2, ['test', 'test1'])
    print(name_list)

    以上就是python使用insert添加列表元素,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python insert
    品易云
    上一篇:python创建列表的方法整理 下一篇:python查找列表元素的两种方法

    相关文章推荐

    • python单分支结构是什么• python二分支结构如何理解• python多分支结构是什么• python小整数池是什么• python inter机制是什么意思• python表达式是什么• python复合赋值运算符是什么• python字符串之间的运算• python逻辑运算符and的使用• python逻辑运算符or的介绍• python Workbook对象如何使用• python中Excel图表的绘制• python创建列表的方法整理

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网