[Tutor] Using __init__ to return a value
Khalid Al-Ghamdi
emailkgnow at gmail.com
Wed Jun 12 11:32:22 CEST 2013
Hi,
Why doesn't this work? And is there way to have an
object immediately return a value or object once it is instantiated with
using a method call?
1. >>> class k:
2. def __init__(self,n):
3. return n*n
4.
5.
6. >>> khalid=k(3)
7. Traceback (most recent call last):
8. File "<pyshell#58>", line 1, in <module>
9. khalid=k(3)
10. TypeError: __init__() should return None, not 'int'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130612/96c6b22a/attachment-0001.html>
More information about the Tutor
mailing list