1.

Explain _str_ with an example.

Answer»

_str_ returns a string representation of a Point object. If a class provides a method named _str _, it overrides the default behavior of the Python built-in

_str_ function.

>>> p = Point(3, 4)

>>> str(p)

‘(3,4)’

Printing a Point object implicitly invokes _str_ on the object, so*- defining _str_

also changes the behavior of print:

>>> p = Point(3,4)

>>> print p(3,4)



Discussion

No Comment Found