n is a object,what means: s='n' ?
Hans Nowak
hnowak at cuci.nl
Fri Aug 31 09:54:09 EDT 2001
>===== Original Message From "Formalin" <formalin14 at email.com.cn> =====
>class now:
> ....
> ....
> ....
>n=now()
>s='n'
>print s
>
>
>the result:<__main__.now instance at 00B2EB0C>
>
>what means?????
I'm assuming you mean the backquote ` here. `x` is a shorthand for repr(x),
which returns the "representation" of object x. This is a string that contains
information about the object, or in some cases a string that can be run
through eval() to return a copy of the object (e.g. the reprs of lists and
dicts). This is also what the interactive interpreter shows. E.g.
>>> 2
2
>>> repr(2)
'2'
>>> a = [1,2,3]
>>> a
[1, 2, 3]
>>> repr(a)
'[1, 2, 3]'
>>> eval(repr(a))
[1, 2, 3]
For classes, it returns a default value, as long as you don't define its
__repr__ method:
>>> class Foo:
def __init__(self, x):
self.x = x
def __repr__(self):
return "I'm a happy class with value '%s'!" % self.x
>>> f = Foo(42)
>>> f
I'm a happy class with value '42'!
>>> repr(f)
"I'm a happy class with value '42'!"
HTH,
--Hans Nowak
More information about the Python-list
mailing list