Python论坛  - 讨论区

标题:[python-chinese] python class methods identity?

2007年11月23日 星期五 15:29

Roc Zhou chowroc.z+l在gmail.com
星期五 十一月 23 15:29:20 HKT 2007

Hello,

I'm now being confused by this segment of code:
>>> class Test:
...     var = 1
...     def func(self): pass
...
>>> x = Test()
>>> y = Test()
>>> x.var is y.var
True
>>> x.func is y.func
False
>>> id(x.var); id(y.var)
146132400
146132400
>>> id(x.func); id(y.func)
-1208243388
-1208243388

Since both "var" and "func" are the variable of the class object, and
x.var is y.var, why x.func is not y.func while their id() return the
same value.

Thanks.

-- 
------------------------------------------------------------------------
My Projects:
http://sourceforge.net/projects/crablfs
http://www.yourlfs.org/
http://www.yourlfs.org/#ru_data_man
http://www.yourlfs.org/tree.html
http://www.yourlfs.org/sysadm_zh_CN.html
My Blog:
http://chowroc.blogspot.com/
Looking for a space and platform to exert my originalities (for my
projects)...
-------------- 下一部分 --------------
??HTML?????...
URL: http://python.cn/pipermail/python-chinese/attachments/20071123/7ed734ae/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年11月23日 星期五 15:33

littlesea littlesea wzhlittlesea在gmail.com
星期五 十一月 23 15:33:38 HKT 2007

var ÊÇÀàµÄ¾²Ì¬±äÁ¿°É£¬º¯ÊýÊÇʵÀýÓ¦¸Ã²»Ò»Ñù

2007/11/23, Roc Zhou <chowroc.z+l在gmail.com>:
>
> Hello,
>
> I'm now being confused by this segment of code:
> >>> class Test:
> ...     var = 1
> ...     def func(self): pass
> ...
> >>> x = Test()
> >>> y = Test()
> >>> x.var is y.var
> True
> >>> x.func is y.func
> False
> >>> id(x.var); id(y.var)
> 146132400
> 146132400
> >>> id(x.func); id(y.func)
> -1208243388
> -1208243388
>
> Since both "var" and "func" are the variable of the class object, and
> x.var is y.var, why x.func is not y.func while their id() return the
> same value.
>
> Thanks.
>
> --
> ------------------------------------------------------------------------
> My Projects:
> http://sourceforge.net/projects/crablfs
> http://www.yourlfs.org/
> http://www.yourlfs.org/#ru_data_man
> http://www.yourlfs.org/tree.html
> http://www.yourlfs.org/sysadm_zh_CN.html
> My Blog:
> http://chowroc.blogspot.com/
> Looking for a space and platform to exert my originalities (for my
> projects)...
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071123/042f599c/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年11月23日 星期五 15:37

Roc Zhou chowroc.z+l在gmail.com
星期五 十一月 23 15:37:01 HKT 2007

ÄÇô id() ·´Ó³µÄÊÇʲôÄØ£¿

¶øÇÒÕâÊDz»ÊÇÒâζ×Å x.func ºÍ y.func ÒªÕ¼¾ÝÁ½²¿·ÖÄÚ´æÄØ£¿

On Nov 23, 2007 3:33 PM, littlesea littlesea <wzhlittlesea在gmail.com> wrote:

> var ÊÇÀàµÄ¾²Ì¬±äÁ¿°É£¬º¯ÊýÊÇʵÀýÓ¦¸Ã²»Ò»Ñù <http://python.cn/mailman/listinfo/python-chinese>
>



-- 
------------------------------------------------------------------------
My Projects:
http://sourceforge.net/projects/crablfs
http://www.yourlfs.org/
http://www.yourlfs.org/#ru_data_man
http://www.yourlfs.org/tree.html
http://www.yourlfs.org/sysadm_zh_CN.html
My Blog:
http://chowroc.blogspot.com/
Looking for a space and platform to exert my originalities (for my
projects)...
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071123/0e9fa29e/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年11月23日 星期五 15:42

haur hekun06在gmail.com
星期五 十一月 23 15:42:26 HKT 2007

¿ÉÄÜÎÊÌâ³öÔÚ is ÉÏ£¬
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071123/a6f31e0f/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年11月23日 星期五 16:04

Roc Zhou chowroc.z+l在gmail.com
星期五 十一月 23 16:04:17 HKT 2007

ÉÏÃæÊÇÔÚ Linux ÏÂÔËÐеĽá¹û¡£ÏÂÃæÊÇ Windows ÏÂÔËÐеĽá¹û£º

>>> class Test:
    var = 1
    def func(self): pass
>>> x = Test()
>>> y = Test()
>>> x.var is y.var
True
>>> x.func is y.func
False
>>> id(x.var)
11228488
>>> id(y.var)
11228488
>>> id(x.func)
14430976
>>> id(y.func)
14433656
>>>

~ÔÎ~

On Nov 23, 2007 3:42 PM, haur <hekun06在gmail.com> wrote:

> ¿ÉÄÜÎÊÌâ³öÔÚ is ÉÏ£¬
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



-- 
------------------------------------------------------------------------
My Projects:
http://sourceforge.net/projects/crablfs
http://www.yourlfs.org/
http://www.yourlfs.org/#ru_data_man
http://www.yourlfs.org/tree.html
http://www.yourlfs.org/sysadm_zh_CN.html
My Blog:
http://chowroc.blogspot.com/
Looking for a space and platform to exert my originalities (for my
projects)...
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071123/7e11609f/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号