SlideShare a Scribd company logo
2
Object-oriented programming
• Python is an object-oriented programming language.
• Unlike Java, Python doesn't force you to use the object-oriented paradigm
exclusively.
• Python also supports procedural programming with modules and functions,
so you can select the most suitable programming paradigm for each part of
your program.
“Generally, the object-oriented paradigm is suitable when you want to group
state (data) and behavior (code) together in handy packets of functionality.”
Most read
3
The class Statement
Syntax:
class classname:
statement(s)
Example:
Class baabtra :
def hello(self) :
print "Hello"
A method defined inside a class body
will always have a mandatory first
parameter, conventionally named self,
that refers to the instance on which
you call the method.
Most read
22
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Most read
Introduction To Python
Object Oriented Programming
Object-oriented programming
• Python is an object-oriented programming language.
• Unlike Java, Python doesn't force you to use the object-oriented paradigm
exclusively.
• Python also supports procedural programming with modules and functions,
so you can select the most suitable programming paradigm for each part of
your program.
“Generally, the object-oriented paradigm is suitable when you want to group
state (data) and behavior (code) together in handy packets of functionality.”
The class Statement
Syntax:
class classname:
statement(s)
Example:
Class baabtra :
def hello(self) :
print "Hello"
A method defined inside a class body
will always have a mandatory first
parameter, conventionally named self,
that refers to the instance on which
you call the method.
Instances
Syntax
anInstance = Class_name( )
Example
baabObject = baabtra( )
_ _init_ _
• When a class has a method named _ _init_ _, calling the class object
implicitly executes _ _init_ _ on the new instance to perform any
instance-specific initialization that is needed.
class baabtra:
def _ _init_ _(self,n):
self.x = n
baabtraInstance = baabtra(42)
Inheritance
Syntax
Derived_class(Base class_name[,Base class_name1][,Base class_name2][,...])
Example
class Baabte:
def amethod(self): print "Baaabte"
class Baabtra(Baabte):
def amethod(self): print "Baabtra“
aninstance = Baaabtra ( )
aninstance.amethod( ) # prints Baabtra
Modules
• A typical Python program is made up of several source files. Each
source file corresponds to a module, which packages program code
and data for reuse.
• Modules are normally independent of each other so that other
programs can reuse the specific modules they need.
• A module explicitly establishes dependencies upon another
module by using import or from statements.
The import Statement
Syntax
import modname [as varname][,...]
Example
import MyModule1
import MyModule as Alias
The import Statement
Syntax
import modname [as varname][,...]
Example
import MyModule1
import MyModule as Alias
In the simplest and most
common case, modname is an
identifier, the name of a variable
that Python binds to the module
object when the import
statement finishes
The import Statement
Syntax
import modname [as varname][,...]
Example
import MyModule1
import MyModule as Alias
looks for the module named
MyModule and binds the
variable named Alias in the
current scope to the module
object. varname is always a
simple identifier.
The from Statement
Syntax
from modname import attrname [as varname][,...]
from modname import *
example
• from MyModule import f
The from Statement
Syntax
from modname import attrname [as varname][,...]
from modname import *
example
• from MyModule import f Importing only one attribut
which is named as ‘f’
The Relative import
employees
employeeDetails.py
HRAccounts
My_project
userBill.py
Suppose we are here and we want to
import the file empleeDetails.py which
resides in a directory as shown
The Relative import
employees
employeeDetails.py
HRAccounts
My_project
userBill.py
import sys
import os
str_current_path = os.getcwd() ## get current working directory
str_module_path = str_current_path.replace( ' Accounts',‘HR/employees / ')
sys.path.append( str_module_path )
import employeeDetails
The Relative import
sys.path
– A list of strings that specifies the search path for modules
sys.path.append( module path )
– This statement append our module path with the existing list of
sys.path, then the import statement search for the module in the
module path as we specified.
_ _ main _ _
• When the Python interpreter reads a source file, it executes all of the code found
in it. But Before executing the code, it will define a few special variables.
• For example, if the python interpreter is running a module (the source file) as
the main program, it sets the special __name__ variable to have a
value"__main__".
• If this file is being imported from another module, __name__ will be set to the
module's name.
def func():
print("func() in one.py")
print("top-level in one.py")
if __name__ == "__main__":
print("one.py is being run directly")
else:
print("one.py is being imported into another
module")
import one
print("top-level in two.py")
one.func()
if __name__ == "__main__":
print("two.py is being run directly")
else:
print("two.py is being imported into
another module")
# file two.py# file one.py
Example
def func():
print("func() in one.py")
print("top-level in one.py")
if __name__ == "__main__":
print("one.py is being run directly")
else:
print("one.py is being imported into another
module")
import one
print("top-level in two.py")
one.func()
if __name__ == "__main__":
print("two.py is being run directly")
else:
print("two.py is being imported into
another module")
# file two.py# file one.py
Example
When we run one.py
-----------------------------
Top-level in one.py
One.py is being run directly
def func():
print("func() in one.py")
print("top-level in one.py")
if __name__ == "__main__":
print("one.py is being run directly")
else:
print("one.py is being imported into another
module")
import one
print("top-level in two.py")
one.func()
if __name__ == "__main__":
print("two.py is being run directly")
else:
print("two.py is being imported into
another module")
# file two.py# file one.py
Example
When we run two.py
-----------------------------
Top-level in one.py
one.py is being imported into another module
Top-level in two.py
Func() in one.py
two.py is being run directly
Questions?
“A good question deserve a good grade…”
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Ph:9895767088
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

More Related Content

What's hot (20)

Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and Sets
Nicole Ryan
 
Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in python
Santosh Verma
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
baabtra.com - No. 1 supplier of quality freshers
 
Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)
Dr. SURBHI SAROHA
 
Methods in java
Methods in javaMethods in java
Methods in java
chauhankapil
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
Emertxe Information Technologies Pvt Ltd
 
Modules in Python Programming
Modules in Python ProgrammingModules in Python Programming
Modules in Python Programming
sambitmandal
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
BMS Institute of Technology and Management
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
BG Java EE Course
 
Object Oriented Programming in Python
Object Oriented Programming in PythonObject Oriented Programming in Python
Object Oriented Programming in Python
Sujith Kumar
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Edureka!
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Ramish Suleman
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
Praveen M Jigajinni
 
Database connectivity in python
Database connectivity in pythonDatabase connectivity in python
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
Python Dictionaries and Sets
Python Dictionaries and SetsPython Dictionaries and Sets
Python Dictionaries and Sets
Nicole Ryan
 
Class, object and inheritance in python
Class, object and inheritance in pythonClass, object and inheritance in python
Class, object and inheritance in python
Santosh Verma
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Edureka!
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)
Dr. SURBHI SAROHA
 
Modules in Python Programming
Modules in Python ProgrammingModules in Python Programming
Modules in Python Programming
sambitmandal
 
Object Oriented Programming in Python
Object Oriented Programming in PythonObject Oriented Programming in Python
Object Oriented Programming in Python
Sujith Kumar
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
BHUVIJAYAVELU
 
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Edureka!
 

Viewers also liked (9)

Object Oriented Programming : Part 2
Object Oriented Programming : Part 2Object Oriented Programming : Part 2
Object Oriented Programming : Part 2
Madhavan Malolan
 
Ian Sommerville, Software Engineering, 9th Edition Ch1
Ian Sommerville,  Software Engineering, 9th Edition Ch1Ian Sommerville,  Software Engineering, 9th Edition Ch1
Ian Sommerville, Software Engineering, 9th Edition Ch1
Mohammed Romi
 
Ian Sommerville, Software Engineering, 9th Edition Ch2
Ian Sommerville,  Software Engineering, 9th Edition Ch2Ian Sommerville,  Software Engineering, 9th Edition Ch2
Ian Sommerville, Software Engineering, 9th Edition Ch2
Mohammed Romi
 
Ch3-Software Engineering 9
Ch3-Software Engineering 9Ch3-Software Engineering 9
Ch3-Software Engineering 9
Ian Sommerville
 
Fundamentals of Database system
Fundamentals of Database systemFundamentals of Database system
Fundamentals of Database system
philipsinter
 
Ian Sommerville, Software Engineering, 9th Edition Ch 4
Ian Sommerville,  Software Engineering, 9th Edition Ch 4Ian Sommerville,  Software Engineering, 9th Edition Ch 4
Ian Sommerville, Software Engineering, 9th Edition Ch 4
Mohammed Romi
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering ppt
shruths2890
 
Software engineering lecture notes
Software engineering lecture notesSoftware engineering lecture notes
Software engineering lecture notes
Siva Ayyakutti
 
Introduction To Software Engineering
Introduction To Software EngineeringIntroduction To Software Engineering
Introduction To Software Engineering
Leyla Bonilla
 
Object Oriented Programming : Part 2
Object Oriented Programming : Part 2Object Oriented Programming : Part 2
Object Oriented Programming : Part 2
Madhavan Malolan
 
Ian Sommerville, Software Engineering, 9th Edition Ch1
Ian Sommerville,  Software Engineering, 9th Edition Ch1Ian Sommerville,  Software Engineering, 9th Edition Ch1
Ian Sommerville, Software Engineering, 9th Edition Ch1
Mohammed Romi
 
Ian Sommerville, Software Engineering, 9th Edition Ch2
Ian Sommerville,  Software Engineering, 9th Edition Ch2Ian Sommerville,  Software Engineering, 9th Edition Ch2
Ian Sommerville, Software Engineering, 9th Edition Ch2
Mohammed Romi
 
Ch3-Software Engineering 9
Ch3-Software Engineering 9Ch3-Software Engineering 9
Ch3-Software Engineering 9
Ian Sommerville
 
Fundamentals of Database system
Fundamentals of Database systemFundamentals of Database system
Fundamentals of Database system
philipsinter
 
Ian Sommerville, Software Engineering, 9th Edition Ch 4
Ian Sommerville,  Software Engineering, 9th Edition Ch 4Ian Sommerville,  Software Engineering, 9th Edition Ch 4
Ian Sommerville, Software Engineering, 9th Edition Ch 4
Mohammed Romi
 
Software Engineering ppt
Software Engineering pptSoftware Engineering ppt
Software Engineering ppt
shruths2890
 
Software engineering lecture notes
Software engineering lecture notesSoftware engineering lecture notes
Software engineering lecture notes
Siva Ayyakutti
 
Introduction To Software Engineering
Introduction To Software EngineeringIntroduction To Software Engineering
Introduction To Software Engineering
Leyla Bonilla
 
Ad

Similar to Object oriented programming in python (20)

Class 12 CBSE Chapter: python libraries.pptx
Class 12 CBSE Chapter: python libraries.pptxClass 12 CBSE Chapter: python libraries.pptx
Class 12 CBSE Chapter: python libraries.pptx
AravindVaithianadhan
 
Python modules
Python modulesPython modules
Python modules
Smt. Indira Gandhi College of Engineering, Navi Mumbai, Mumbai
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
Singamvineela
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Python Programming - Functions and Modules
Python Programming - Functions and ModulesPython Programming - Functions and Modules
Python Programming - Functions and Modules
Omid AmirGhiasvand
 
Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12
JAYASURYANSHUPEDDAPA
 
library-basics python.pptx for education
library-basics python.pptx for educationlibrary-basics python.pptx for education
library-basics python.pptx for education
ShubhamShinde648276
 
CLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptxCLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptx
seccoordpal
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptx
krushnaraj1
 
Modules in Python.docx
Modules in Python.docxModules in Python.docx
Modules in Python.docx
manohar25689
 
Object Oriented Programming in Python.pptx
Object Oriented Programming in Python.pptxObject Oriented Programming in Python.pptx
Object Oriented Programming in Python.pptx
grpvasundhara1993
 
Python classes objects
Python classes objectsPython classes objects
Python classes objects
Smt. Indira Gandhi College of Engineering, Navi Mumbai, Mumbai
 
Python_Unit_2 OOPS.pptx
Python_Unit_2  OOPS.pptxPython_Unit_2  OOPS.pptx
Python_Unit_2 OOPS.pptx
ChhaviCoachingCenter
 
UNIT-5 object oriented programming lecture
UNIT-5 object oriented programming lectureUNIT-5 object oriented programming lecture
UNIT-5 object oriented programming lecture
w6vsy4fmpy
 
Django
DjangoDjango
Django
Mohamed Ramadan
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
KALAISELVI P
 
python-fefedfasdgsgfahfdshdhunctions-190506123237.pptx
python-fefedfasdgsgfahfdshdhunctions-190506123237.pptxpython-fefedfasdgsgfahfdshdhunctions-190506123237.pptx
python-fefedfasdgsgfahfdshdhunctions-190506123237.pptx
avishekpradhan24
 
Introduction to python programming 2
Introduction to python programming   2Introduction to python programming   2
Introduction to python programming 2
Giovanni Della Lunga
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdf
Daddy84
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
amiable_indian
 
Class 12 CBSE Chapter: python libraries.pptx
Class 12 CBSE Chapter: python libraries.pptxClass 12 CBSE Chapter: python libraries.pptx
Class 12 CBSE Chapter: python libraries.pptx
AravindVaithianadhan
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
Singamvineela
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Python Programming - Functions and Modules
Python Programming - Functions and ModulesPython Programming - Functions and Modules
Python Programming - Functions and Modules
Omid AmirGhiasvand
 
Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12
JAYASURYANSHUPEDDAPA
 
library-basics python.pptx for education
library-basics python.pptx for educationlibrary-basics python.pptx for education
library-basics python.pptx for education
ShubhamShinde648276
 
CLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptxCLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptx
seccoordpal
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptx
krushnaraj1
 
Modules in Python.docx
Modules in Python.docxModules in Python.docx
Modules in Python.docx
manohar25689
 
Object Oriented Programming in Python.pptx
Object Oriented Programming in Python.pptxObject Oriented Programming in Python.pptx
Object Oriented Programming in Python.pptx
grpvasundhara1993
 
UNIT-5 object oriented programming lecture
UNIT-5 object oriented programming lectureUNIT-5 object oriented programming lecture
UNIT-5 object oriented programming lecture
w6vsy4fmpy
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
KALAISELVI P
 
python-fefedfasdgsgfahfdshdhunctions-190506123237.pptx
python-fefedfasdgsgfahfdshdhunctions-190506123237.pptxpython-fefedfasdgsgfahfdshdhunctions-190506123237.pptx
python-fefedfasdgsgfahfdshdhunctions-190506123237.pptx
avishekpradhan24
 
Introduction to python programming 2
Introduction to python programming   2Introduction to python programming   2
Introduction to python programming 2
Giovanni Della Lunga
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdf
Daddy84
 
Introduction to Python - Part Three
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
amiable_indian
 
Ad

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
baabtra.com - No. 1 supplier of quality freshers
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
baabtra.com - No. 1 supplier of quality freshers
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
baabtra.com - No. 1 supplier of quality freshers
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
baabtra.com - No. 1 supplier of quality freshers
 
Blue brain
Blue brainBlue brain
Blue brain
baabtra.com - No. 1 supplier of quality freshers
 
5g
5g5g
5g
baabtra.com - No. 1 supplier of quality freshers
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
baabtra.com - No. 1 supplier of quality freshers
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
baabtra.com - No. 1 supplier of quality freshers
 

Recently uploaded (20)

Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
The case for on-premises AI
The case for on-premises AIThe case for on-premises AI
The case for on-premises AI
Principled Technologies
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
UiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build PipelinesUiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build Pipelines
UiPathCommunity
 
Contributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptxContributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptx
Patrick Lumumba
 
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptxECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
Jasper Oosterveld
 
Dev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API WorkflowsDev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API Workflows
UiPathCommunity
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
UiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build PipelinesUiPath Community Zurich: Release Management and Build Pipelines
UiPath Community Zurich: Release Management and Build Pipelines
UiPathCommunity
 
Contributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptxContributing to WordPress With & Without Code.pptx
Contributing to WordPress With & Without Code.pptx
Patrick Lumumba
 
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptxECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
Jasper Oosterveld
 
Dev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API WorkflowsDev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API Workflows
UiPathCommunity
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 

Object oriented programming in python

  • 1. Introduction To Python Object Oriented Programming
  • 2. Object-oriented programming • Python is an object-oriented programming language. • Unlike Java, Python doesn't force you to use the object-oriented paradigm exclusively. • Python also supports procedural programming with modules and functions, so you can select the most suitable programming paradigm for each part of your program. “Generally, the object-oriented paradigm is suitable when you want to group state (data) and behavior (code) together in handy packets of functionality.”
  • 3. The class Statement Syntax: class classname: statement(s) Example: Class baabtra : def hello(self) : print "Hello" A method defined inside a class body will always have a mandatory first parameter, conventionally named self, that refers to the instance on which you call the method.
  • 4. Instances Syntax anInstance = Class_name( ) Example baabObject = baabtra( )
  • 5. _ _init_ _ • When a class has a method named _ _init_ _, calling the class object implicitly executes _ _init_ _ on the new instance to perform any instance-specific initialization that is needed. class baabtra: def _ _init_ _(self,n): self.x = n baabtraInstance = baabtra(42)
  • 6. Inheritance Syntax Derived_class(Base class_name[,Base class_name1][,Base class_name2][,...]) Example class Baabte: def amethod(self): print "Baaabte" class Baabtra(Baabte): def amethod(self): print "Baabtra“ aninstance = Baaabtra ( ) aninstance.amethod( ) # prints Baabtra
  • 7. Modules • A typical Python program is made up of several source files. Each source file corresponds to a module, which packages program code and data for reuse. • Modules are normally independent of each other so that other programs can reuse the specific modules they need. • A module explicitly establishes dependencies upon another module by using import or from statements.
  • 8. The import Statement Syntax import modname [as varname][,...] Example import MyModule1 import MyModule as Alias
  • 9. The import Statement Syntax import modname [as varname][,...] Example import MyModule1 import MyModule as Alias In the simplest and most common case, modname is an identifier, the name of a variable that Python binds to the module object when the import statement finishes
  • 10. The import Statement Syntax import modname [as varname][,...] Example import MyModule1 import MyModule as Alias looks for the module named MyModule and binds the variable named Alias in the current scope to the module object. varname is always a simple identifier.
  • 11. The from Statement Syntax from modname import attrname [as varname][,...] from modname import * example • from MyModule import f
  • 12. The from Statement Syntax from modname import attrname [as varname][,...] from modname import * example • from MyModule import f Importing only one attribut which is named as ‘f’
  • 13. The Relative import employees employeeDetails.py HRAccounts My_project userBill.py Suppose we are here and we want to import the file empleeDetails.py which resides in a directory as shown
  • 14. The Relative import employees employeeDetails.py HRAccounts My_project userBill.py import sys import os str_current_path = os.getcwd() ## get current working directory str_module_path = str_current_path.replace( ' Accounts',‘HR/employees / ') sys.path.append( str_module_path ) import employeeDetails
  • 15. The Relative import sys.path – A list of strings that specifies the search path for modules sys.path.append( module path ) – This statement append our module path with the existing list of sys.path, then the import statement search for the module in the module path as we specified.
  • 16. _ _ main _ _ • When the Python interpreter reads a source file, it executes all of the code found in it. But Before executing the code, it will define a few special variables. • For example, if the python interpreter is running a module (the source file) as the main program, it sets the special __name__ variable to have a value"__main__". • If this file is being imported from another module, __name__ will be set to the module's name.
  • 17. def func(): print("func() in one.py") print("top-level in one.py") if __name__ == "__main__": print("one.py is being run directly") else: print("one.py is being imported into another module") import one print("top-level in two.py") one.func() if __name__ == "__main__": print("two.py is being run directly") else: print("two.py is being imported into another module") # file two.py# file one.py Example
  • 18. def func(): print("func() in one.py") print("top-level in one.py") if __name__ == "__main__": print("one.py is being run directly") else: print("one.py is being imported into another module") import one print("top-level in two.py") one.func() if __name__ == "__main__": print("two.py is being run directly") else: print("two.py is being imported into another module") # file two.py# file one.py Example When we run one.py ----------------------------- Top-level in one.py One.py is being run directly
  • 19. def func(): print("func() in one.py") print("top-level in one.py") if __name__ == "__main__": print("one.py is being run directly") else: print("one.py is being imported into another module") import one print("top-level in two.py") one.func() if __name__ == "__main__": print("two.py is being run directly") else: print("two.py is being imported into another module") # file two.py# file one.py Example When we run two.py ----------------------------- Top-level in one.py one.py is being imported into another module Top-level in two.py Func() in one.py two.py is being run directly
  • 20. Questions? “A good question deserve a good grade…”
  • 21. Want to learn more about programming or Looking to become a good programmer? Are you wasting time on searching so many contents online? Do you want to learn things quickly? Tired of spending huge amount of money to become a Software professional? Do an online course @ baabtra.com We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
  • 22. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 23. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Ph:9895767088 Start up Village Eranakulam, Kerala, India. Email: [email protected]