zoukankan      html  css  js  c++  java
  • python 列表中插入自定义类的疑惑

    Python 2.7.4 (default, Apr 19 2013, 18:32:33)
    [GCC 4.7.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class Person:                                #我自定义的类
    ...     def setname(self,name):
    ...             self.name=name
    ...
    >>> list=[ ]                                            #建立一个空列表
    >>> temp=Person()
    >>> temp.setname('a')
    >>> list.append(temp)
    >>> list[0].name
    'a'                                                        #将temp追加到list中后,list[0].name 的值为‘a’
    >>> temp.setname('b')
    >>> list.append(temp)
    >>> list[0].name                                  #经过上两步后,居然list[0]和list[1] 的值都改变了
    'b'
    >>> list[1].name
    'b'
    >>> del temp                                     #删除之前存在的temp后,又重新定义一个,就没有问题了
    >>> temp=Person()
    >>> temp.setname('c')
    >>> list.append(temp)
    >>> list[0].name
    'b'
    >>> list[1].name
    'b'
    >>> list[2].name
    'c'
    >>>

  • 相关阅读:
    dbt macro 说明
    构建一个dbt 数据库适配器
    dbt 包的构建
    dbt 生产环境使用
    来自官方的一些dbt 最佳实践
    knowledge-repo 知识管理简单试用
    dbt 包管理
    dbt 的知识文档管理
    knowledge 开源知识管理系统
    hasura graphql server 集成gitlab
  • 原文地址:https://www.cnblogs.com/tcstory/p/3320615.html
Copyright © 2011-2022 走看看