June 2000
Intermediate to advanced
556 pages
8h 45m
English
Python allows you to add the names of parameters to function and method calls. This naming can help make the code easier to read, especially when there are lots of parameters.
CD-ROM reference=6045.txt
class Account:
...
def __repr__(self):
"""
Return executable form
"""
return 'Account (balance=%d,name="%s")' %
(self.Balance,self.Name)
>>> from accounts import Account
>>> a = Account (100,"Sean")
>>> print a
Account Object: Balance is '100'. Account Name is 'Sean'
>>> s = repr(a)
>>> print s
Account (balance=100,name="Sean")
>>> b = eval (s)
>>> print b
Account Object: Balance is '100'. Account Name is 'Sean'
Read now
Unlock full access