Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Python OOps

The document discusses object oriented programming concepts like object, class, inheritance, polymorphism, abstraction, encapsulation. It provides examples of defining a class, creating objects, using constructor, instance variables and methods. It also explains different types of variables that can be used like local, instance, static variables and self reference variable.

Uploaded by

anjalibathula23
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Python OOps

The document discusses object oriented programming concepts like object, class, inheritance, polymorphism, abstraction, encapsulation. It provides examples of defining a class, creating objects, using constructor, instance variables and methods. It also explains different types of variables that can be used like local, instance, static variables and self reference variable.

Uploaded by

anjalibathula23
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

OOPS:

------
OOPS: Stands for Object oriented Programing System.

python is fully secure program.


------------------------------
1 object
2. class
3. inheritence
4. polymorphism
5. abstraction
6. encpsulation
=================

Object means a real-world entity such as a pen, chair, table,


computer, watch,
etc. Object-Oriented Programming is a methodology
or paradigm to design a program using classes and objects.
It simplifies software development and maintenance
by providing some concepts:
----------------------------
1 object
--------
object is a real wolrd entity
ex: fan ,pen,byke,oppo mobile ...etc
the physical entity is object
visable thing

2. class
---------
--> class is one container
but it is logical contianer
eg:
---
faculty
------
bank:
in visable thing

human: renuka:
vehicle: car
---------------------
3. inheritence
----------------------
process of sharing code form one class to another class class
parent class new class is chid class
-->

4. polymorphism
----------------
poly : many
morphism: forms

1. method overloading
2. method overriding
----------------------
5. abstraction:
---------------
public
private
protected

-->
atm:
----
6. encpsulation
=================
-->
Advantage of OOPs

1) OOPs makes development and maintenance easier.


2) OOPs provides data hiding.
3) OOPs provide reuseability
4) opps provide scurity:
----------------------------------------
1. Object:
---------------
--> The object is a real world entity
--> an object is an instence of class
--> an objcet is a physical entity
--> object is visable thing
eg:
---
fan,bike,mobile_phone,priya,anjali...car, pen.....etc
-->

object has 3 characteristics


--------------------------------
1. state: the object values is known as state
2. behaviour:the functionality of object is known as behaviour
3.identity:we required momory (object creation)when we create object
it has one unique identity.

Eg:
----
navya
----
state:hieght, weight, color......etc (Properties)
behaviour:sleep(), walk(), run().....etc (Funtionality)
identity:memory allocation (unigue)

fan
----
state:color,cost,no_ofwings, company ...etc
behaviour:rotation_on(), rotation_off().....etc
identity: power unique memory location in heap area (PVM).

Bike:
----
state: color, cost,shape, company_name,tyre_name.....etc
behaviour: start(), stop()
identity: memory allocation

-------------------------------------------------
sbi atm
-------
--> acc_no,acc_name,balance...etc
--> withdraw(),deposit().pin_gen().....etc

wayed:
-------

--> hieght,color,weight,..etc
--> walk(),sleep(),run(),eat()..etc
honda bike
----------
color,cc_value,cost,company_name.....etc

--> engine_start(),stop(),rinding()....etc

======================================
--> the main use of object is to provide memory to the class

syntax:
-------
object_name=class_name()

eg:
---
a=ATM()
f=Fan()
h=Honda_Bike()
n=Navya()
=======================================
Class:
---------
--> class is collection of object
--> class is collection of variables,methods ,constructors.
--> class is model,or blue print.
--> we can write a class to reprasent properties(attributes) and
behaviour (functions-methods) of object.
--> properties can be reprasent by variables
--> Actions can be reprasent by methods (functions)

--> when we create class. class not occupies any memory


when we create object then class can occupies the memory.

-->

how to define class


--------------------
we can define a classs by using class keyword
------------------------------------------------
syntax:
----------
class class_name():
'''document section'''
variables:staic,local and instence
methods:instence methods,static method,class method

syntax: for object creation


-----------------------------
object=class_name()
=====================================

class Student:
variables
methods
s=Student()

--------------------
class Atm:
variables
methods
a=Atm()
a.variable
a.method_name()

-------------------------------------------
eg1:
class Student:
def insert(cls):
cls.sid=120 #instence variable
cls.sname="Navya"
def display(cls):
print(cls.sid,"\t",cls.sname)

s=Student()
s.insert()
s.display()
# cls:--> current class intence variable or it is reference variable

-------------------------------------------
Example
----------
class Student:
def m1(self): # current class intences
self.id=int(input("Enter Your id value:"))
self.name=input("Enter your name")
print("MY id=",self.id)
print("My name=",self.name)
obj=Student()
print(id(obj))
obj.m1()
obj.m1()

output
-------
2386168090976
Enter Your id value:100
Enter your namePriya
MY id= 100
My name= Priya
Enter Your id value:200
Enter your namenavya
MY id= 200
My name= navya

--------------------------
class Student:
def m1(self): # current class intences / object
self.id=int(input("Enter Your id value:"))
self.name=input("Enter your name")
print("MY id=",self.id)
print("My name=",self.name)

s=Student()
s.m1()
s.m1()
---------------------------------------
class Student:
def m1(self,sid,sname): # current class intences / object
self.id=sid
self.name=sname
print("MY id=",self.id)
print("My name=",self.name)

s=Student()
s.m1(100,"NihariPriya")
s.m1(200,"Anjali")
s.m1(300,"Navya")

# here sid and sname are local variable


# self.sid,self.sname is known as instence variable
====================================================

Program for employee record using with class and object?


-------------------------------------------------------
eid
ename
esalary
eaddress
email_id
emobile_no

-----------------------
with static values
with input funstion
with pass value throught object
-----------------------------------
=============================================
3 types variable
------------------
1. global variable
2. local
3. non-local
=======================
at class level
-------------
3 types
-------------
1. local variable (inside method)
2. instence variable( object level variable with self keyword)
3. reference variable (variable refer by the class name)
4. static variable( class level variable)

---------------------------------
class Student:
def m1(self):
self.id=120
self.name='sai'
print("MY id=",self.id)
print("My name=",self.name)
def m2(self):
print("MY id=",self.id)
print("My name=",self.name)
def m3(self):
print("MY id=",self.id)
print("My name=",self.name)
obj=Student()
print(id(obj))
obj.m1()
obj.m2()
obj.m3()

========================================
# program for variable
class Emp:
company="TCS" static variable
def __init__(self,eid,ename): # here eid and ename are local variable
self.eid=eid
self.ename=ename # self.eid,self.ename are instence variable
def print_value(self):
print("My id=",self.eid)
print("my name=",self.ename)
e1=Emp(100,'Yakub') # here e1 is a reference variable
e1.print_value()

=================================================
class Emp:
def insert_record(self,eid,ename,esal): # local variable
self.eid=eid
self.ename=ename
self.esal=esal
def print_record(self):
print("My id=",self.eid)
print("my name=",self.ename)
e1=Emp()
e1.insert_record(99,'aryan',90000.98)
e1.print_record()
e2=Emp()
e2.insert_record(199,'Renuka',190000.98)
e2.print_record()
e3=Emp()
e3.insert_record(1,'wayed',990000.98)
e3.print_record()

============================================

class Emp:
def insert_record(self):
self.eid=int(input("Enter eid value:"))
self.ename=input("Enter Your name:")
self.esal=float(input("Enter emp salary:"))
def print_record(self):
print("My id=",self.eid)
print("my name=",self.ename)
print("my name=",self.esal)
e1=Emp()
e1.insert_record()
e1.print_record()
e2=Emp()
e2.insert_record()
e2.print_record()
e3=Emp()
e3.insert_record()
e3.print_record()
==========================================
self: variable
---------------

self is the defualt variable which is always pointing current class


object(like this key word)
--> by using self we can access current class instence variable
and current class methods

eg:

def m1(self):

def __init__(self):

self.varaibale_nme=value

=======================================
constructors
-----------------
--> constructor is a special method in a python
--> in python constructor define with __init__(self)
--> constructor will be executed automatically at the time of
objcet creation.
--> The main purpose of constructor is to declare and initialize instence
variable.
--> per object constructor will execute only once.
--> constructor can take atleast one argument(i.e self).

eg:
---
class Con_Demo:
def __init__(self):
print("Constructor executed with out calling with object")
def sms(self):
print("My Own Method")

obj=Con_Demo()
ob=Con_Demo()
ob.sms()

====================================
eg2:
----
class Emp:
def __init__(self):
self.eid=int(input("Enter eid value:"))
self.ename=input("Enter Your name:")
self.esal=float(input("Enter emp salary:"))
def print_record(self):
print("My id=",self.eid)
print("my name=",self.ename)
print("my name=",self.esal)
e1=Emp()
e1.print_record()
e2=Emp()
e2.print_record()
e3=Emp()
e3.print_record()
===========================================
eg:
---
class Emp:
def __init__(self,eid,ename,esal):
self.eid=eid
self.ename=ename
self.esal=esal
def print_record(self):
print("My id=",self.eid)
print("my name=",self.ename)
print("my name=",self.esal)
e1=Emp(100,'aryan',9000.99)
e1.print_record()
e2=Emp(99,'ksv',7890.88)
e2.print_record()

=========================================
1. program for student record?
2. program for employess record?
3. program for ATM mechine?

----------------------------------------

You might also like