zoukankan      html  css  js  c++  java
  • Python中变量的绑定,或者说引用

    print('The simple assignment')
    shoppingList = ['chicken','mango','apple','banana']
    myList = shoppingList
    
    print('Before any action')
    print('The shopping list is',shoppingList)
    print('my list is',myList,'
    ')
    
    print('Del the first item from the shopping list')
    del myList[0]
    print('the shopping list is',shoppingList)
    print('my list is',myList,'
    ')
    
    print('Copy and then del')
    myList = shoppingList[:]
    del myList[0]
    print('the shopping list is',shoppingList)
    print('my list is',myList,'
    ')
    
    #原对象改变,被原对象赋值的变量也随着改变
    #被赋值的变量改变,原对象也改变
    #变量指向对象在内存中的地址,所以删除了地址上的内容,对大家都有影响
    #如果采用切片方式取得值的话,就没有影响

     2015/4/19 by Kerita

  • 相关阅读:
    电影观后感
    自定义内存管理
    web.xml配置详解
    Annotation
    Centos中yum方式安装java
    linux下添加用户并赋予root权限
    Injector
    Container
    GlassFish的安装与使用(Windows)
    Version Control
  • 原文地址:https://www.cnblogs.com/kerita/p/4447896.html
Copyright © 2011-2022 走看看