To-string conversion
Topics: to-string conversion, __repr__, __str__ Updated: 2020-10-04
To-string conversion Today we are going to look at the two methods that control how an object is converted into a string object. When we just print an object, we won’t get a useful representation. For example, when trying to print the bromley instance:
bromley = CastleKilmereMember(name='Bromley Huckabee', birthyear=1959, sex='male') print(bromley) We get this output: <__main__.CastleKilmereMember object at 0x7f81853bfc50>. It contains the name of the class an the ID of the object (its memory address).