码迷,mamicode.com
首页 > 编程语言 > 详细

Python 复制与赋值

时间:2014-12-12 16:29:02      阅读:146      评论:0      收藏:0      [点我收藏+]

标签: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‘]

  

Python 复制与赋值

标签:blog   ar   sp   on   div   log   bs   ef   as   

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

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