本文實例講述了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程序設計有所幫助。
新聞熱點
疑難解答
圖片精選