码迷,mamicode.com
首页 > 其他好文 > 详细

对象与参考

时间:2017-10-18 21:36:46      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:make   enc   making   out   conf   tin   参考   not   another   

# Filename: reference.py

print ‘Simple Assignment‘
shoplist = [‘apple‘, ‘mango‘, ‘carrot‘, ‘banana‘]
mylist = shoplist # mylist is just another name pointing to the same object!

del shoplist[0]

print ‘shoplist is‘, shoplist
print ‘mylist is‘, mylist
# notice that both shoplist and mylist both print the same list without
# the ‘apple‘ confirming that they point to the same object

print ‘Copy by making a full slice‘
mylist = shoplist[:] # make a copy by doing a full slice
del mylist[0] # remove first item

print ‘shoplist is‘, shoplist
print ‘mylist is‘, mylist
# notice that now the two lists are different

对象与参考

标签:make   enc   making   out   conf   tin   参考   not   another   

原文地址:http://www.cnblogs.com/nku-wangfeng/p/7688958.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!