Object oriented
# Oops
# class oriented
'''
class RailwayForm:
formType = "RailwayForm"
def printData(self):
print(f"name is {self.name}")
print(f"train is {self.train}")
application = RailwayForm()
application.name = "Onam"
application.train = "Rajdhani Express"
application.printData()
'''
# Class attibution
'''
class Employee:
company = "Google"
harry = Employee()
rajani = Employee()
harry.salary = 300
rajani.salary = 400
print(harry.company)
print(rajani.company)
Employee.company = "youtube"
print(harry.company)
print(rajani.company)
print(harry.salary)
print(rajani.salary)
'''
'''
# instant attribution
class Employee:
company = "Google"
salary = 100
harry = Employee()
rajani = Employee()
# Creating instant attribute salary for both the objects
# harry.salary = 300
# rajani.salary = 400
harry.salary = 40
print(harry.salary)
print(rajani.salary)
# below line throw an error as address in not present in isinstance/class
# print(rajani.address)
'''
'''
class Employee:
company = "Google"
def getSalary(self):
print(f"salary of this employee who working in {self.company} is {self.salary}")
harry = Employee()
harry.salary = 10000
harry.getSalary() #Employee.getSalary(harry)
'''
static method
class Employee:
company = "Google"
def getSalary(self):
print(f"salary of this employee who working in {self.company} is {self.salary}")
@staticmethod
def greet():
print("good morning")
@staticmethod
def time():
print("your time over ")
harry = Employee()
harry.salary = 10000
harry.getSalary() #Employee.getSalary(harry)
harry.greet()
harry.time()
constructor
class Employee:
company = "Google"
def __init__(self,name,salary,subunit):
self.name = name
self.salary = salary
self.subunit = subunit
print("Employee is created")
def getDetails (self):
print(f"The name of the employee is {self.name}")
print(f"The salary of the employee is {self.salary}")
print(f"The subunit of the employee is {self.subunit}")
harry = Employee("harry",100,"Youtube")
harry.getDetails()
Comments
Post a Comment