Posts

Showing posts from August 11, 2021

Diamond Shape problem in python.

  Diamond Shape problem in python. Code -  ------------------------------------- class A:     def met(self):         return "Hello this is a diamond shape problem of class A" class B(A):     def met(self):         return "Hello this is a diamond shape problem of class B" class C(A):     def met(self):         return "Hello this is a diamond shape problem of class C " class D(B, C):     def met(self):         return "Hello this is a diamond shape problem of class D" a = A() b = B() c = C() d = D() print(d.met())

Over & Super in python.

 Over & Super in python. Code - ------------------------------ class A : classvar1 = "Class variable of class A" def __init__ ( self ): self .var1 = "Instance variable of class A" self .special = "This is special variable" self .instance_variable = "Instance variable of class A" class B (A): classvar1 = "Class variable of class B" def __init__ ( self ): self .var1 = "Instance variable of class B" self .instance_variable = "Instance variable of class B" super (). __init__ () # print(super(B, self).classvar1) hello = A() by = B() # print(by.special) print (by.var1, by.instance_variable) # print(by.var1) # print(by.classvar1)