1
2class Person:
3 name = ""
4 age = 0
5
6 def __init__(self, personName, personAge):
7 self.name = personName
8 self.age = personAge
9
10 def __repr__(self):
11 return {'name':self.name, 'age':self.age}
12
13 def __str__(self):
14 return 'Person(name='+self.name+', age='+str(self.age)+ ')'
15
1import datetime
2now = datetime.datetime.now()
3now.__str__()
4#>>> '2020-12-27 22:28:00.324317'
5now.__repr__()
6#>>> 'datetime.datetime(2020, 12, 27, 22, 28, 0, 324317)'