possibly a dumb question
Peter Hansen
peter at engcorp.com
Sat Jun 29 21:51:17 EDT 2002
Adonis wrote:
>
> can a class return a value? i have treid to google this, but have found
> myself short of an answer, i know i could place it in a member and retrieve
> it or through a function, but im trying to simplify my life.. just a
> little..
You probably don't actually mean a class. I think you mean an object,
which is an instance of a class. (If I've got that wrong, I think
we need clarification of the question.)
If that's the case, there's still one more problem left. :-)
"Returning a value" is a concept related to calling a method
or function. It doesn't have any particular meaning if you
ask "can an object return a value?" unless you mean something
like "can a method of an object return a value?". That is
certainly possible, although I'm not this is what you wanted,
either:
>>> class MyClass:
... def myMethod(self):
... return 'spam'
...
>>> c = MyClass()
>>> print 'Green eggs and %s.' % c.myMethod()
Green eggs and spam.
Can you ask the question in a different way, or show an example
of what you were hoping to do?
-Peter
More information about the Python-list
mailing list