手机
当前位置:查字典教程网 >脚本专栏 >python >python实现给数组按片赋值的方法
python实现给数组按片赋值的方法
摘要:本文实例讲述了python实现给数组按片赋值的方法。分享给大家供大家参考。具体如下:这段代码可以直接给数组的第5-7个元素赋值invento...

本文实例讲述了python实现给数组按片赋值的方法。分享给大家供大家参考。具体如下:

这段代码可以直接给数组的第5-7个元素赋值

inventory = ["sword", "armor", "shield", "healing potion"] inventory[4:6] = ["orb of future telling"] print inventory

运行结果如下:

['sword', 'armor', 'shield', 'healing potion', 'orb of future telling']

希望本文所述对大家的Python程序设计有所帮助。

【python实现给数组按片赋值的方法】相关文章:

python批量导出导入MySQL用户的方法

Python enumerate遍历数组示例应用

python实现DNS正向查询、反向查询的例子

python list 合并连接字符串的方法

python实现问号表达式(?)的方法

python中定义结构体的方法

Python实现扫描指定目录下的子目录及文件的方法

Python列表推导式的使用方法

使用python实现strcmp函数功能示例

python两种遍历字典(dict)的方法比较

精品推荐
分类导航