possibly a dumb question
peter at engcorp.com
Sun Jun 30 03:51:17 CEST 2002
> 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
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,
>>> 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?
More information about the Python-list