zoukankan      html  css  js  c++  java
  • object and namespace

    http://effbot.org/zone/python-objects.htm

    几点总结:

    (1) 类的基本属性

          . id, returned by id(obj)

          . type, returned by type(obj)

          . some content

          . methods; some objects have methods to change the content, and some don’t; eg, list vs. turple

          . names

    (2) namespace

          . namespace are pairs of (name, object reference). eg., n=10 where ‘n’ is the name and ‘10’ is the int object.

          . names are not really properties of objects

    (3) assignment

          举例说明。

         name = 10

         name = 20

         . add name ‘name’ to local namespace, and refer it to an integer object containing value 10

         . refer name to another integer object containing value 20

         . the original object ‘10’ is not affected by this operation and it doesn’t care

         再举一个object可变的例子。

         name = []

         name.append(a)

         . add name ‘name’ to a local namespace, and refer it to an empty list object; this modifies the namespace

         . an object method is called; this modifies the content of the the list object, but it doesn’t touch the namespace

    (4) note

          Things like name.attr and name[index] are just syntactic sugar for method calls.

          The first corresponds to __setattr__/__getattr__, the second to __setitem__/__getitem__ (depending on which side of the assignment they appear).

          --> syntactic suger是指为了更容易阅读而设计出来的编程语言的语法

  • 相关阅读:
    English trip V2-B 14 Yes, I can! 是的,我能! Teacher:Russell
    I1-3 Weather Teacher:Corrine
    4-redis数据过期策略
    redis持久化
    redis优势
    解决error while loading shared libraries
    1-zookeeper基本原理和使用
    ObjectiveSQL框架让你不要再写复杂SQL
    sharding-proxy+sharding-ui安装使用配置
    vim 多行取消注释
  • 原文地址:https://www.cnblogs.com/freshair_cnblog/p/7285349.html
Copyright © 2011-2022 走看看