Code:
class MyClass:
def __init__(self, param1=None, param2=None):
if param1 is not None and param2 is not None:
# Constructor with both parameters
self.param1 = param1
self.param2 = param2
elif param1 is not None:
# Constructor with only param1
self.param1 = param1
self.param2 = "default_value_for_param2"
else:
# Default constructor with no parameters
self.param1 = "default_value_for_param1"
self.param2 = "default_value_for_param2"
def display_params(self):
print(f"param1: {self.param1}, param2: {self.param2}")
# Example usage
obj1 = MyClass()
obj1.display_params() # Output: param1: default_value_for_param1, param2: default_value_for_param2
obj2 = MyClass("value1")
obj2.display_params() # Output: param1: value1, param2: default_value_for_param2
obj3 = MyClass("value1", "value2")
obj3.display_params() # Output: param1: value1, param2: value2