2004年08月27日 星期五 22:49
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
2004年08月27日 星期五 23:25
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
Zeuux © 2025
京ICP备05028076号