USE OF SELF, INIT IN PYTHON AND COMPARISON OF TWO OBJECTS VALUE

in GEMS5 years ago

Just revising myself some basic concepts of init method and self keyword in python.

class Person:
    def __init__(self,age):
        self.age=age
    def displayAge(self):
        return self.age
    def updateAge(self):
        return 25
    
    def compare(self,other):
        if self.age==other.age:
            return True
        else:
            return False
        
    
first=Person(25)
second=Person(23)
#first.displayAge()
# first.updateAge()


if first.compare(second):
    print("They are same")
else:
    print("They are different")


The output when executed is as follows:

Screenshot_2.png