-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12. Q6.py
More file actions
27 lines (22 loc) · 819 Bytes
/
12. Q6.py
File metadata and controls
27 lines (22 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'''Write a program to create a class Date that has a list containing day,
month and year attributes. Define an overloaded == operator to compare two
Date object'''
class Date:
def __init__(self, day, month, year):
self.date = [day, month, year] # Store date components in a list
def __eq__(self, other):
if isinstance(other, Date):
return self.date == other.date
return False
def __str__(self):
return f"{self.date[0]:02d}/{self.date[1]:02d}/{self.date[2]}"
# Example usage
date1 = Date(5, 5, 2025)
date2 = Date(5, 5, 2025)
date3 = Date(6, 5, 2025)
print("Date1:", date1)
print("Date2:", date2)
print("Date3:", date3)
# Comparison
print("Date1 == Date2?", date1 == date2) # True
print("Date1 == Date3?", date1 == date3) # False