Feb-19-2017, 05:24 AM
the code:
from __future__ import print_function total = 1 class Classy: total = 0 def __init__(self): return def add(self,a): p = self.total self.total += a return p if __name__ == '__main__': c = Classy print('c =',repr(c)) print(dir(c)) for n in range(3): x = c.add(8) print('x =',repr(x))i ran it under python3:
Output:lt1/forums /home/forums 48> py3 min1.py
c = <class '__main__.Classy'>
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'add', 'total']
Traceback (most recent call last):
File "min1.py", line 16, in <module>
x = c.add(8)
TypeError: add() missing 1 required positional argument: 'a'
lt1/forums /home/forums 49>
what did i miss in learning about classes?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.