Python Tutorials

Python Overloading and Overriding 0

Python Overloading and Overriding

Program 1 # Program for overloading and overrding # class Test: # def addition(self,a=0,b=0,c=0,d=0): # z=a+b+c+d # return(z) # #calling # T=Test() # print(T.addition(10,20,30,40)) # 4 Arguments # print(T.addition(10,20,30)) # 3 Arguments # print(T.addition(10,20))...

Python super() Function 0

Python super() Function

Program 1 #Super method in python # class A: # def __init__(self): # print(“A”) # class B(A): # def __init__(self): # super().__init__() # print(“B”) # class C(B): # def __init__(self): # super().__init__() # print(“C”)...

Abstract Class in Python 0

Abstract Class in Python

Program 1 # Abstract class and methods from abc import ABC,abstractmethod # class Button(ABC): # @abstractmethod # def click(self): # None # class Color(Button): # None # # def click(self): # # print(“Its Red...

IS-A and HAS-A Relation in Python 0

IS-A and HAS-A Relation in Python

Program 1 # Program for isA and HasA Relation class Employee: def setEId(self,eid): self.eid=eid def setEName(self,ename): self.ename=ename def setESalary(self,esalary): self.esalary=esalary def setEDept(self,edept): self.edept=edept def getEId(self): return self.eid def getEName(self): return self.ename def getESalary(self): return...

Getter and Setter in Python 0

Getter and Setter in Python

Program 1 # Example of Setters and Getters class Student: def setId(self,id): self.id=id def getId(self): return self.id def setName(self,name): self.name=name def getName(self): return self.name def setCourse(self,course): self.course=course def getCourse(self): return self.course #Calling S=Student() S.setId(101)...

Inner Class in Python 0

Inner Class in Python

Program 1 #Inner Class in Python # class TestOuter: # def __init__(self): # print(“Hello i am init method of outer class”) # class TestInner: # def __init__(self): # print(“Hello i am init method of...

Data Hiding in Python 0

Data Hiding in Python

Program 1 #how to read password(Hidden data) # import getpass as gp # userid=input(“Enter User Name: “) # password=gp.getpass(“Enter Password: “) # print(“User Name: “,userid) # print(“Password: “,password) import pwinput userid=input(“Enter User Name: “)...

Python Static Variables and Methods 0

Python Static Variables and Methods

Program 1 #Program for static variables,method and class method # class Test: # def __init__(self): # self.n=10 # def increment(self): # self.n=self.n+1 # #calling # T1=Test() # T2=Test() # T1.increment() # T1.increment() # T1.increment()...

Polymorphism in Python 0

Polymorphism in Python

Program 1 #Polymorphism in python #Method Overloading and Operator overloading class Test: def addition(self,a=0,b=0,c=0,d=0): return a+b+c+d #calling T1=Test() print(T1.addition(10,20,30,40)) print(T1.addition(10,20,30)) print(T1.addition(10,20)) print(T1.addition(10)) print(T1.addition()) Program 2 # Operator overloading # a=”Hello” # b=”Indore” # print(type(a))...

Inheritance in Python 0

Inheritance in Python

Program 1 #Inheritance in Python # # class First: # def add(self,a,b): # return(a+b) # class Second(First): # def sub(self,a,b): # return(a-b) # def multi(self,a,b): # return(a*b) # # calling # s=Second() # print(s.sub(10,5))...