Question
Python programming: Write a class with a constructor (should take 2 arguments), destructor, and instance method to display the 2 arguments. and add class method
Python programming: Write a class with a constructor (should take 2 arguments), destructor, and instance method to display the 2 arguments. and add class method in bottom program.
class MyClass:
def __init__(self, arg1, arg2):
# Constructor
self.arg1 = arg1
self.arg2 = arg2
def __del__(self):
# Destructor:
pass
def display(self):
# Instance method:
print(f"arg1: {self.arg1}, arg2: {self.arg2}")
obj = MyClass("food", "bar") # Create an instance of MyClass
# Calls the display method
obj.display() # prints "arg1: food, arg2: bar"
del obj # Delete the instance
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started