Tuesday 17 July 2018

Python __str__ Method

Cited from the book "Python How to Program"

For example,
hourly = HourlyWorker( "Bob", "Smith", 40.0, 10.00 ) # create an object from the class

 print hourly # invoke __str__ implicitly
 print hourly.__str__() # invoke __str__ explicitly
 print HourlyWorker.__str__( hourly ) # explicit, unbound call, and the __str__ method defined takes only one argument 'self'.




No comments:

Post a Comment