脚本专栏 
首页 > 脚本专栏 > 浏览文章

python实现给数组按片赋值的方法

(编辑:jimmy 日期: 2025/6/22 浏览:3 次 )

本文实例讲述了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中subprocess的简单使用示例
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。