do al objects in python have str and repr functions code example
Example 1: python repr
# The repr() function returns a printable representational string of the given object.
>>> var = 'foo'
>>> print(repr(var))
"'foo'"
Example 2: string function in class python
class Person:
name = ""
age = 0
def __init__(self, personName, personAge):
self.name = personName
self.age = personAge
def __repr__(self):
return {'name':self.name, 'age':self.age}
def __str__(self):
return 'Person(name='+self.name+', age='+str(self.age)+ ')'