首页 > 代码库 > Python 复制与赋值
Python 复制与赋值
用‘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 = shoplistdel mylist[0]print ‘shoplist is:‘,shoplistprint ‘mylist is:‘,mylistprint ‘Copy by making a full slice‘mylist= shoplist[:]del shoplist[0]print ‘shoplist is:‘,shoplistprint ‘mylist is:‘,mylist
$python reference.pySimple Assignmentshoplist is: [‘mango‘, ‘carrot‘, ‘banana‘]mylist is: [‘mango‘, ‘carrot‘, ‘banana‘]Copy by making a full sliceshoplist is: [‘carrot‘, ‘banana‘]mylist is: [‘mango‘, ‘carrot‘, ‘banana‘]
Python 复制与赋值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。