python 列表赋值操作可能存在的潜在问题
生活随笔
收集整理的這篇文章主要介紹了
python 列表赋值操作可能存在的潜在问题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
import copyprint("++++++++++++++++++++ 版本1 ++++++++++++++++++++")
newItemList = [1,2,3,4,5]
print("newItemList is : ", newItemList)tempList = newItemList
print("tempList is : ", tempList)tempList.remove(4)
print("tempList is : ", tempList)
print("newItemList is : ", newItemList)
?
?
?
import copyprint("\n++++++++++++++++++++ 版本2 ++++++++++++++++++++") newItemList = [1,2,3,4,5] print("newItemList is : ", newItemList)tempList = copy.deepcopy(newItemList) print("tempList is : ", tempList)tempList.remove(4)print("tempList is : ", tempList) print("newItemList is : ", newItemList)?
?
import copyprint("\n++++++++++++++++++++ 版本3 ++++++++++++++++++++") newItemList = [1,2,3,4,5] print("newItemList is : ", newItemList)tempList = copy.copy(newItemList) print("tempList is : ", tempList)tempList.remove(4)print("tempList is : ", tempList) print("newItemList is : ", newItemList)?
?
import copyprint("\n++++++++++++++++++++ 版本4 ++++++++++++++++++++") newItemList = [1,2,3,4,5] print("newItemList is : ", newItemList)tempList = [] tempList = newItemList print("tempList is : ", tempList)tempList.remove(4)print("tempList is : ", tempList) print("newItemList is : ", newItemList)?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的python 列表赋值操作可能存在的潜在问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 获得当前运行脚本文件的路径
- 下一篇: torch.roll() 详解