repr example 1

This commit is contained in:
Mert Gör ☭ 2023-07-15 15:03:47 +03:00
parent a5b8fac0eb
commit f400a3195c
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9
1 changed files with 13 additions and 0 deletions

View File

@ -0,0 +1,13 @@
class Date:
def __init__(self, day, month, year):
self.day = day
self.month = month
self.year = year
def __repr__(self):
return 'Date object: {}/{}/{}'.format(self.day, self.month, self.year)
d = Date(10, 12, 2008)
print(d) # Date object: 10/12/2008
print(str(d)) # Date object: 10/12/2008
print(repr(d)) # Date object: 10/12/2008