Program - class to print user defined message whenever object of class is called is called.


Topic: Program - class to print user defined message whenever object of class is called is called.

Solution

class User:
    def __init__(self, msg="Demo of custom message by repr and str in class"):
        self.msg = msg
    def __repr__(self):
        return f"Object of User class is called with parameter {self.msg}"
    def __str__(self):
        return f"Object of User class is called with parameter {self.msg}"



List all Python Programs