this constructor takes no arguments (defining class)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • python101
    New Member
    • Sep 2007
    • 90

    this constructor takes no arguments (defining class)

    [code=python]
    class double:
    def __ini__(self,x1 ,y2):
    self._x=x1
    self._y=y2

    def result(self):
    return (self._x)*(self ._y)

    def x2(self):
    return 2*self._result( )

    >>> a=double(10,1)
    Traceback (most recent call last):
    File "<pyshell#7 >", line 1, in <module>
    a=double(10,1)
    TypeError: this constructor takes no arguments
    [/code]
    what's wrong in my code?
  • elcron
    New Member
    • Sep 2007
    • 43

    #2
    Originally posted by python101
    [code=python]
    class double:
    def __ini__(self,x1 ,y2):
    self._x=x1
    self._y=y2

    def result(self):
    return (self._x)*(self ._y)

    def x2(self):
    return 2*self._result( )

    >>> a=double(10,1)
    Traceback (most recent call last):
    File "<pyshell#7 >", line 1, in <module>
    a=double(10,1)
    TypeError: this constructor takes no arguments
    [/code]
    what's wrong in my code?
    [code=python]
    class double:
    def __init__(self,x 1,y2):
    self._x=x1
    self._y=y2

    def result(self):
    return (self._x)*(self ._y)

    def x2(self):
    return 2*self._result( )
    [/code]
    __init__ is the constructor for a class. You left out the t

    Comment

    Working...