标签:blog ar sp on div log bs ef as
用‘b=a’复制,对变量a,b的操作都会对a指向的对象起作用。
用‘b=a[]’赋值,则只是赋值。
#!/usr/bin/env python # -*- coding: utf-8 -*- # Filename:reference.py __author__ = ‘JerryQiu‘ print ‘Simple Assignment‘ shoplist = [‘apple‘,‘mango‘,‘carrot‘,‘banana‘] mylist = shoplist del mylist[0] print ‘shoplist is:‘,shoplist print ‘mylist is:‘,mylist print ‘Copy by making a full slice‘ mylist= shoplist[:] del shoplist[0] print ‘shoplist is:‘,shoplist print ‘mylist is:‘,mylist
$python reference.py Simple Assignment shoplist is: [‘mango‘, ‘carrot‘, ‘banana‘] mylist is: [‘mango‘, ‘carrot‘, ‘banana‘] Copy by making a full slice shoplist is: [‘carrot‘, ‘banana‘] mylist is: [‘mango‘, ‘carrot‘, ‘banana‘]
标签:blog ar sp on div log bs ef as
原文地址:http://www.cnblogs.com/monkeyfather/p/4159858.html