471,330 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

this constructor takes no arguments (defining class)

Expand|Select|Wrap|Line Numbers
  1. class double:
  2.         def __ini__(self,x1,y2):
  3.                 self._x=x1
  4.                 self._y=y2
  5.  
  6.         def result(self):
  7.                 return (self._x)*(self._y)
  8.  
  9.         def x2(self):
  10.                 return 2*self._result()
  11.  
  12. >>> a=double(10,1)
  13. Traceback (most recent call last):
  14.   File "<pyshell#7>", line 1, in <module>
  15.     a=double(10,1)
  16. TypeError: this constructor takes no arguments
  17.  
what's wrong in my code?
Oct 7 '07 #1
1 8656
elcron
43
Expand|Select|Wrap|Line Numbers
  1. class double:
  2.         def __ini__(self,x1,y2):
  3.                 self._x=x1
  4.                 self._y=y2
  5.  
  6.         def result(self):
  7.                 return (self._x)*(self._y)
  8.  
  9.         def x2(self):
  10.                 return 2*self._result()
  11.  
  12. >>> a=double(10,1)
  13. Traceback (most recent call last):
  14.   File "<pyshell#7>", line 1, in <module>
  15.     a=double(10,1)
  16. TypeError: this constructor takes no arguments
  17.  
what's wrong in my code?
Expand|Select|Wrap|Line Numbers
  1. class double:
  2.         def __init__(self,x1,y2):
  3.                 self._x=x1
  4.                 self._y=y2
  5.  
  6.         def result(self):
  7.                 return (self._x)*(self._y)
  8.  
  9.         def x2(self):
  10.                 return 2*self._result()
  11.  
__init__ is the constructor for a class. You left out the t
Oct 7 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Sergey Krushinsky | last post: by
34 posts views Thread by Jason Heyes | last post: by
6 posts views Thread by scottyman | last post: by
7 posts views Thread by Ron | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.