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']
    

      

  • 相关阅读:
    hoj 13832 Fence
    hoj 13830 DNA Sequencing 字典树
    HOJ Funfair
    HOJ 13828 Funfair
    图论相关
    01字典树
    异或
    日常补题2017-10-31
    康拓展开
    日常训练17-10-27(16杭州ccpc)
  • 原文地址:https://www.cnblogs.com/monkeyfather/p/4159858.html
Copyright © 2011-2022 走看看