zoukankan      html  css  js  c++  java
  • 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 = 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']
    

      

  • 相关阅读:
    P4999 烦人的数学作业
    P3413 SAC#1
    P2657 [SCOI2009]windy数
    P2602 [ZJOI2010]数字计数
    JSOI2007 建筑抢修
    CF161B Discounts
    Description
    Street Numbers
    Pizza Cutting
    Supermean
  • 原文地址:https://www.cnblogs.com/monkeyfather/p/4159858.html
Copyright © 2011-2022 走看看