classes

inshu chauhan insideshoes at gmail.com
Wed Oct 24 08:11:15 EDT 2012


I was just trying out a programme for learning classes in python

The prog below is showing an error which it should not show :

class Bag:
    def __init__(self, x):
        self.data = []

    def add(self, x):
        self.data.append(x)
    def addtwice(self, x):
         self.add(x)
         self.add(x)
y = Bag(4)
print " Adding twice of %4.2f gives " % (y.addtwice())


Error is :

Traceback (most recent call last):
  File "Z:\learning Python\learn5.py", line 35, in <module>
    print " Adding twice of %4.2f gives " % (y.addtwice())
TypeError: addtwice() takes exactly 2 arguments (1 given)

why the prog is having this error with self nd x as arguments ???
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121024/ed555df9/attachment.html>


More information about the Python-list mailing list