29_9_2022 Python Lab(Thursday)

 class buzz:

    a=1

    def __init__(self,n):

        print("The constructor is called!")

        a=n

    def a_func(self):

        print("Buenos Dias!")

    def bar(self,something):

        def foo(self):

            print("We are inside the foo func!")

        return foo

    def __str__(self):

        return ("This is the str block")


#Inheriting from the buzz class

def buzz2(buzz):

    b=2

    __name=""

    def __init__(self,num,name):

        print("This is the init block of the buzz2 class")

        self.b=num

        self.__name=name

    def a_func2(self):

        print("Buenas Noches!")

    def __str__():

        pass

    def a_func2(self,time_of_the_day):

        print("Hello, it's "+time_of_the_day)

"""Person class"""

class person:

    def __init__(self,name,age):

        print("Inside the init block of person class")

        self.name=name

        self.age=age

    def __str__(self):

        print("Inside the str func of person class")

        return "Hola, "+self.name+" esta "

class demo1:

    def __init__(self,num2):

        self.n=num2

    def __add__(self,other_obj):

        return self.n+other_obj.n

    def __gt__(self,obj):

        return self.n>obj.n

    def __lt__(self,obj):

        return "You have used __lt__ function"

def main():

    buzz1=buzz(23)

    print(buzz1)

if __name__=="__main__":

    print("Calling main insede theif block")

    main()

Comments

Popular Posts