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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!