设为首页 加入收藏

TOP

object and namespace
2017-09-30 17:21:26 】 浏览:9482
Tags: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是指为了更容易阅读而设计出来的编程语言的语法

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇python django框架开发例子2 下一篇python对象的基本操作代码

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目