首页 > 编程语言 > 详细

Python 复制与赋值

时间:2014-12-12 16:27:25      阅读:278      评论:0      收藏:0      [点我收藏+]

用‘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‘]

  

Python 复制与赋值

原文:http://www.cnblogs.com/monkeyfather/p/4159858.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!