Advanced Python Notes 14.05.2020
Advanced Python Notes 14.05.2020
-------------------------------
PROGRAMMING APPROACHES ARE TWO TYPES.
}
M2()
{
}
MAIN()
{
M1()
M2()
}
EX: C
OOPS PRINCIPLES
1) ENCAPSULATION
2) ABSTRACTION
3) INHERITENCE
4) POLYMORPHISM
class <classname>:
states
behaviours
what is state?
state represents some value
state can be variable or constant
what is variable
a state which represent some value but value can be chaged is called as variable
what is constant
what is state? Ans:- state represnts some value.. state can be variable or
constant..
what is variable? ANs: a state which represnt some value but value can be changed
is called as variable..
what is constant? state which represnt some value but value cant be changed is
called as constant..
types of variables
------------------
in python we have 3 types of variables
1) local varibale
2) instance variable
3) static varibale
1)A varibale which is declared within the function or method is called local
variables.
local varibales we can access only within that function.
2) Instance variable
MyClass.a=10 when
note:
when we r declaring static variable with in class prefixing class name is
optional..but when r declaring static variable inside the static method prefixing
class name is compulosry..
what is Behvaiour?
Ans: .
->in python we can define 2 types of behaviours.
1)method or function or procedure.. 2)cosntructor..
what is method?
Ans: A behvaiour which represent some functionality, will execute when ever
programmer will call is called as method.
Types of methods
in python we will have 3 types of methods 1)instances method 2)static method
3)class method
def<method name(self)>:
<logic>
Types of construcotrs..
-----------------------------
constructors are two types..
1)default constructor or parameter less construcotr.
2)parameterized construcotor
----------------------------------------------
1)what is default constructor or parameter less construcotr.?
------------------------------------
Ans:
while defining a constructor..if we didn't declared any parameter except self
keyword.. which is called as default constructor..
----------------------------------------
<syntax to define default constructor>
---------------------------------------
def __init__(self):
<self.instance variablename>=<value>
task1
------------
define student class
states are:
----------------
stid
stname
stloc
behvaiours are:
-----------------
->parameterized constructor
->DisplayStudentInfo()
----------------------------
task2:
-------------------
define faculty class
states are:
------------------
fid
fname
fphno
behvaiours are:
------------------
->parameterized construcotr
->DisplayFacultyInfo()
Q: one dept can contain more than one employee. But one employee may not belong to
more than one department..
class Department:
def __init__(self,dno,dname):
self.deptno=dno
self.deptname=dname
def DisplayDeptInfo(self):
print("Department Number is:",self.deptno)
print("Department name is:",self.deptname)
class Employee(Department):
def __init__(self,eno,ename,esal):
super().__init__(111,'Technical')
self.empno=eno
self.empname=ename
self.empsal=esal
def DisplayEmpInfo(self):
super().DisplayDeptInfo()
print("Employee No is:",self.empno)
print("Employee Name is:",self.empname)
print("Employee Salary is:",self.empsal)
obj=Employee(111,'rama',1000)
obj.DisplayEmpInfo()
class Department:
def __init__(self,dno,dname):
self.deptno=dno
self.deptname=dname
def DisplayDeptInfo(self):
print("Department Number is:",self.deptno)
print("Department name is:",self.deptname)
class Employee(Department):
def __init__(self,eno,ename,esal):
sup
class Department:
def __init__(self,dno,dname):
self.deptno=dno
self.deptname=dname
def DisplayDeptInfo(self):
print("Department Number is:",self.deptno)
print("Department name is:",self.deptname)
obj=Employee(111,'rama',1000)
obj.DisplayEmpInfo()
8:24 PM: hw
task1
--------------
parrent class
Course
CHild class
student
task2:
---------------
parrent class
course
child class
faculty
task3:
------------------
parrent class
Shop
child class
customer
what is self?
Ans:
self is a keyword which represnt current
class object
super is a keyword.which rerepesnt super
class object
super() is using for
parrent class construcotr or instance method..
class BC:
def __init__(self,x,y):
self.a=x
self.b=y
def DisplayBcInfo(self):
print("a value is:",self.a)
print("b value is:",self.b)
class DC(BC):
def __init__(self,m,n):
super().__init__(10,20)
self.i=m
self.j=n
def DisplayDcInfo(self):
super().DisplayBcInfo()
print("i value is:",self.i)
print("j value is:",self.j)
class TC(DC):
def __init__(self,q,r):
super().__init__(100,200)
self.o=q
self.p=r
def DisplayTcInfo(self):
super().DisplayDcInfo()
print("o value is:",self.o)
print("p value is:",self.p)
obj=TC(1000,2000)
obj.DisplayTcInfo()
===================================
class Department:
def __init__(self,dno,dname):
self.dno=dno
self.dname=dname
def DisplayDeptInfo(self):
print("department no is:",self.dno)
print("department name is:",self.dname)
class Branch(Department):
def __init__(self,bid,bname):
super().__init__(10,'HR')
self.branchid=bid
self.branchname=bname
def DisplayBranchInfo(self):
super().DisplayDeptInfo()
print("branch id is:",self.branchid)
print("branch name is:",self.branchname)
class Employee(Branch):
def __init__(self,eno,ename,esal):
super().__init__(123,'Hyd')
self.empno=eno
self.empname=ename
self.empsal=esal
def DisplayEmpInfo(self):
super().DisplayBranchInfo()
print("Employee No is:",self.empno)
print("Employee Name is:",self.empname)
print("Employee salary is:",self.empsal)
obj=Employee(111,'rama',1000)
obj.DisplayEmpInfo()