Python论坛  - 讨论区

标题:[python-chinese] python参数和self的迷惑

2004年08月27日 星期五 22:49

lizzz49 lizzz49 at 163.com
Fri Aug 27 22:49:09 HKT 2004

class A(object):
    def __init__(self,a):
        self.a =a
    def __str__(self):
        return "this is " + self.a
    def equals(self,b):
        print one
        print two
        return  one.a == b.a
one = A("one")
two = A("two")
if one.equals(two):
    print "equals\n"

>>> 
this is one
this is two
>>> 
这里的one ,two为A的实例
为什么在定义的时候就能使用了呢?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20040827/cc802eca/attachment.htm

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

2004年08月27日 星期五 23:25

limodou chatme at 263.net
Fri Aug 27 23:25:55 HKT 2004

lizzz49,您好!

	仍然是在执行equals时才执行的呀,那里看出是定义时生效的,多加些print看看就知道了。

======= 2004-08-27 22:49:09 您在来信中写道:=======

>class A(object):
>    def __init__(self,a):
>        self.a =a
>    def __str__(self):
>        return "this is " + self.a
>    def equals(self,b):
>        print one
>        print two
>        return  one.a == b.a
>one = A("one")
>two = A("two")
>if one.equals(two):
>    print "equals\n"
>
>>>> 
>this is one
>this is two
>>>> 
>这里的one ,two为A的实例
>为什么在定义的时候就能使用了呢?_______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese
>

= = = = = = = = = = = = = = = = = = = =
			

        致
礼!
 
				 
        limodou
        chatme at 263.net
          2004-08-27


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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号