PYTHON PROGRAMMING

VI. CLASSES AND OBJECTS

Engr. Ranel O. Padon
PYTHON PROGRAMMING TOPICS
I

•Introduction to Python Programming

II

•Python Basics

III

•Controlling the Program Flow

IV

•Program Components: Functions, Classes, Packages, and Modules

V

•Sequences (List and Tuples), and Dictionaries

VI

•Object-Based Programming: Classes and Objects

VII

•Customizing Classes and Operator Overloading

VIII

•Object-Oriented Programming: Inheritance and Polymorphism

IX

•Randomization Algorithms

X

•Exception Handling and Assertions

XI

•String Manipulation and Regular Expressions

XII

•File Handling and Processing

XIII

•GUI Programming Using Tkinter
PROGRAMMING PARADIGMS
PROGRAMMING PARADIGMS

• Procedural/Imperative (C, FORTRAN, COBOL)
• Object-Oriented (C++, Java, C#, Objective-C)
Objective-C is used in Apple’s OS X and iOS and for customizing its apps.

• Functional Programming (Lisp)
Lisp is used for customizing AutoCAD

• Logic Programming (Prolog)
• Concurrent (Erlang)
• Multi-Paradigm (Python, Scala, PHP, JavaScript)
•…
PROGRAMMING PARADIGMS

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
PROGRAMMING PARADIGMS

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
PROGRAMMING PARADIGMS

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
PROCEDURE-ORIENTED PROGRAMMING
PROCEDURE-ORIENTED PROGRAMMING
PROCEDURE-ORIENTED PROGRAMMING

1/6) Emphasis is on doing things (algorithms).
2/6) Large programs are divided into smaller programs
known as functions.
3/6) Most of the functions share global data.
PROCEDURE-ORIENTED PROGRAMMING

4/6) Data are more open around the system from function
to function.
5/6) Functions transform data from one form to another.
6/6) Employs top-down approach in program design.
OBJECT-ORIENTED PROGRAMMING
OBJECT-ORIENTED PROGRAMMING
The data of an object can be accessed only by the functions
associated with that object.
Functions of one object can access the functions of other objects.
OBJECT-ORIENTED PROGRAMMING
1/8) Emphasis is on data rather than procedures or algorithms.
2/8) Programs are divided into what are known as objects.
3/8) Data structures are designed such that they characterize
the objects.

4/8) Functions that operate on the data are tied together in
the data structure.
OBJECT-ORIENTED PROGRAMMING
5/8) Data is hidden and cannot be accessed by external functions.
6/8) Objects may communicate with each other through functions.

7/8) New data and functions can be easily added whenever necessary.
8/8) Follows bottom-up approach in program design.
OBJECT-ORIENTED PROGRAMMING
Benefits of OOP:
1/8) Through inheritance, we can eliminate redundant code and extend
the use of existing classes which is not possible in procedure-oriented
approach.
2/8) We can build programs from the standard working modules that
communicate with one another, rather than having to start writing the
code from scratch which happens procedure-oriented approach.
This leads to saving of development time and higher productivity.
OBJECT-ORIENTED PROGRAMMING
Benefits of OOP:
3/8) The principle of data hiding helps the programmer to build secure
programs that cannot be invaded by code in other parts of the program.
4/8) It is possible to have multiple instances of object to co-exist without
any interference.
OBJECT-ORIENTED PROGRAMMING

Benefits of OOP:
5/8) It is possible to map objects in the problem domain
to those in the program.
6/8) It is easy to partition the work in a project based on objects .
OBJECT-ORIENTED PROGRAMMING

Benefits of OOP:
7/8) Object oriented systems can be easily upgraded from small
to large systems.
8/8) Software complexity can be easily managed.
OBJECT-ORIENTED PROGRAMMING
OOP first appeared in the Simula programming language in the 1960s.
OBJECT-ORIENTED PROGRAMMING

• Simula was invented by Ole-Johan Dahl and Kristen Nygaard,
which influenced C++, Java, and C#
• professors Dahl and Nygaard received two very prestigious prizes:
1.) von Neumann medal
2.) Turing prize (the Nobel prize of computer science)
OBJECT-ORIENTED PROGRAMMING
Aspects of OOP
CLASSES

• A class is just like a blueprint of a house.
• An object is the actual house built from that blueprint.

• You could then create numerous houses/objects from a single blueprint.
CLASSES

Two main components of an Object/Class
(these terms are synonymous/equivalent):
• Attributes & Behaviors
• Variables & Functions
• Fields & Methods
• Data Members & Member Functions
CLASSES INSTANTIATION
CLASSES
THE TIME CLASS | Time1.py
THE TIME CLASS | Time1.py
THE TIME CLASS | Time1.py
THE TIME CLASS
THE TIME CLASS
THE TIME CLASS
THE TIME CLASS
THE TIME CLASS
SPECIAL ATTRIBUTES Classes
SPECIAL ATTRIBUTES Classes
SPECIAL ATTRIBUTES Objects
SPECIAL ATTRIBUTES Objects
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Protected Var
OBJECT ATTRIBUTES | Protected Var
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Chaining
Chaining Comparisons in Other Languages

Concise Equivalent in Python
OBJECT ATTRIBUTES | Chaining
Chaining Comparisons
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Set and Get
Raising Exceptions
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Set and Get
OBJECT ATTRIBUTES | Private Var
OBJECT ATTRIBUTES | Private Var
OBJECT ATTRIBUTES | Private Var
CONSTRUCTORS | Default Args
CONSTRUCTORS | Default Args
CONSTRUCTORS | Default Args
CONSTRUCTORS | Default Args
CONSTRUCTORS | Default Args
CONSTRUCTORS | Default Args
CONSTRUCTORS | Default Args
CONSTRUCTORS | Default Args
CONSTRUCTORS | Default Args
DESTRUCTORS
• method called __del__
• executes when the last reference to
an object is deleted or goes out of scope.
• specifies no parameters other than self
• returns None.
DESTRUCTORS
CLASS ATTRIBUTES
Class Attributes are used to track the state of all
objects/instances of a given class.
They are also known as Static Variables
There are also Class Behaviors (Static Methods), methods
that involve all objects/instances of a given class). In Java,
Static Methods are used heavily by the Math class so that you
could execute methods without creating an object of the Math
class
CLASS ATTRIBUTES
CLASS ATTRIBUTES
Lists are not restricted to homogeneous data types.
Python programmers typically use lists
to store sequences of homogeneous values
(values of the same data type)
CLASS ATTRIBUTES
Lists are not restricted to homogeneous data types.
Python programmers typically use lists
to store sequences of homogeneous values
(values of the same data type)
CLASS ATTRIBUTES
COMPOSITION

• Objects usually have attributes of basic/primitive data types
(string, integers, boolean, etc)

• Composition: when objects whose attributes
are themselves references to objects of other classes
COMPOSITION
note the gayagaya() method and the tao1.gayagaya(tao2) statement
COMPOSITION
COMPOSITION
COMPOSITION
COMPOSITION
COMPOSITION
REFERENCES
 Deitel, Deitel, Liperi, and Wiedermann - Python: How to Program (2001).

 Disclaimer: Most of the images/information used here have no proper source citation, and I do
not claim ownership of these either. I don’t want to reinvent the wheel, and I just want to reuse
and reintegrate materials that I think are useful or cool, then present them in another light,
form, or perspective. Moreover, the images/information here are mainly used for
illustration/educational purposes only, in the spirit of openness of data, spreading light, and
empowering people with knowledge. 

More Related Content

PPTX
Python Functions
PPTX
Chapter 05 classes and objects
PDF
Python programming : Classes objects
PPTX
Object oriented programming with python
PDF
Object oriented approach in python programming
PDF
Python programming : Files
PPSX
Modules and packages in python
PPT
Python Pandas
Python Functions
Chapter 05 classes and objects
Python programming : Classes objects
Object oriented programming with python
Object oriented approach in python programming
Python programming : Files
Modules and packages in python
Python Pandas

What's hot (20)

PPTX
Data Analysis with Python Pandas
PPTX
Python decorators
ODP
Python Modules
PPTX
Packages In Python Tutorial
PPTX
Chapter 07 inheritance
PDF
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
PPTX
CLASS OBJECT AND INHERITANCE IN PYTHON
PPT
standard template library(STL) in C++
PDF
Introduction to NumPy (PyData SV 2013)
PPTX
Python Scipy Numpy
PPTX
Python: Modules and Packages
PPTX
Functions in python
PDF
Pandas
PPTX
Object oriented programming in python
PPTX
Class, object and inheritance in python
PDF
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
PPTX
Advanced Python : Decorators
PPTX
Classes, objects in JAVA
PDF
Intents in Android
Data Analysis with Python Pandas
Python decorators
Python Modules
Packages In Python Tutorial
Chapter 07 inheritance
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
CLASS OBJECT AND INHERITANCE IN PYTHON
standard template library(STL) in C++
Introduction to NumPy (PyData SV 2013)
Python Scipy Numpy
Python: Modules and Packages
Functions in python
Pandas
Object oriented programming in python
Class, object and inheritance in python
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Advanced Python : Decorators
Classes, objects in JAVA
Intents in Android
Ad

Viewers also liked (12)

PDF
Python Programming - II. The Basics
PDF
Python Programming - XIII. GUI Programming
PDF
Python Programming - V. Sequences (List and Tuples) and Dictionaries
PDF
Switchable Map APIs with Drupal
PDF
Python Programming - VII. Customizing Classes and Operator Overloading
PDF
Python Programming - III. Controlling the Flow
PDF
Python Programming - IX. On Randomness
PDF
Python Programming - X. Exception Handling and Assertions
PDF
Python Programming - XI. String Manipulation and Regular Expressions
PDF
Python Programming - VIII. Inheritance and Polymorphism
PDF
Python Programming - XII. File Processing
PDF
Python Programming - I. Introduction
Python Programming - II. The Basics
Python Programming - XIII. GUI Programming
Python Programming - V. Sequences (List and Tuples) and Dictionaries
Switchable Map APIs with Drupal
Python Programming - VII. Customizing Classes and Operator Overloading
Python Programming - III. Controlling the Flow
Python Programming - IX. On Randomness
Python Programming - X. Exception Handling and Assertions
Python Programming - XI. String Manipulation and Regular Expressions
Python Programming - VIII. Inheritance and Polymorphism
Python Programming - XII. File Processing
Python Programming - I. Introduction
Ad

Similar to Python Programming - VI. Classes and Objects (20)

PPT
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
PPTX
PPTX
C++ in object oriented programming
PPTX
Python programming Concepts (Functions, classes and Oops concept
PPTX
Introduction to Software - Coder Forge - John Mulhall
PPTX
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
PPTX
OOP-1.pptx
PPT
Share Unit 1- Basic concept of object-oriented-programming.ppt
PPTX
c++.pptxwjwjsijsnsksomammaoansnksooskskk
PDF
lecture.in ooop object orented programmeg.pdf
PPTX
Introduction to Object Oriented Programming in Python.pptx
PPTX
Object Oriented Programming - Copy.pptxb
PPTX
Untitled presentation about object oriented.pptx
PPTX
UNIT - 1 Java Fundamentals, Basics of java
PPTX
Object Oriented Programming WEOBRDSLKBNSDF
PPTX
Summer Training Project On Python Programming
PPTX
Apex code (Salesforce)
PPTX
SE-IT JAVA LAB OOP CONCEPT
PPT
Unit 1- Basic concept of object-oriented-programming.ppt
PPSX
Object Oriented Programming Overview for the PeopleSoft Developer
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
C++ in object oriented programming
Python programming Concepts (Functions, classes and Oops concept
Introduction to Software - Coder Forge - John Mulhall
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
OOP-1.pptx
Share Unit 1- Basic concept of object-oriented-programming.ppt
c++.pptxwjwjsijsnsksomammaoansnksooskskk
lecture.in ooop object orented programmeg.pdf
Introduction to Object Oriented Programming in Python.pptx
Object Oriented Programming - Copy.pptxb
Untitled presentation about object oriented.pptx
UNIT - 1 Java Fundamentals, Basics of java
Object Oriented Programming WEOBRDSLKBNSDF
Summer Training Project On Python Programming
Apex code (Salesforce)
SE-IT JAVA LAB OOP CONCEPT
Unit 1- Basic concept of object-oriented-programming.ppt
Object Oriented Programming Overview for the PeopleSoft Developer

More from Ranel Padon (9)

PDF
The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)
PDF
CKEditor Widgets with Drupal
PDF
Views Unlimited: Unleashing the Power of Drupal's Views Module
PDF
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
PDF
PyCon PH 2014 - GeoComputation
PDF
Power and Elegance - Leaflet + jQuery
PDF
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
PDF
Of Nodes and Maps (Web Mapping with Drupal - Part II)
PDF
Web Mapping with Drupal
The Synergy of Drupal Hooks/APIs (Custom Module Development with ChartJS)
CKEditor Widgets with Drupal
Views Unlimited: Unleashing the Power of Drupal's Views Module
Batch Scripting with Drupal (Featuring the EntityFieldQuery API)
PyCon PH 2014 - GeoComputation
Power and Elegance - Leaflet + jQuery
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Web Mapping with Drupal

Recently uploaded (20)

PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
Architecture types and enterprise applications.pdf
PPT
What is a Computer? Input Devices /output devices
PPT
Geologic Time for studying geology for geologist
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
CloudStack 4.21: First Look Webinar slides
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Comparative analysis of machine learning models for fake news detection in so...
PPTX
Modernising the Digital Integration Hub
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PDF
The influence of sentiment analysis in enhancing early warning system model f...
A review of recent deep learning applications in wood surface defect identifi...
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Benefits of Physical activity for teenagers.pptx
Architecture types and enterprise applications.pdf
What is a Computer? Input Devices /output devices
Geologic Time for studying geology for geologist
Enhancing plagiarism detection using data pre-processing and machine learning...
UiPath Agentic Automation session 1: RPA to Agents
CloudStack 4.21: First Look Webinar slides
OpenACC and Open Hackathons Monthly Highlights July 2025
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Final SEM Unit 1 for mit wpu at pune .pptx
Comparative analysis of machine learning models for fake news detection in so...
Modernising the Digital Integration Hub
Flame analysis and combustion estimation using large language and vision assi...
NewMind AI Weekly Chronicles – August ’25 Week III
Custom Battery Pack Design Considerations for Performance and Safety
Credit Without Borders: AI and Financial Inclusion in Bangladesh
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
The influence of sentiment analysis in enhancing early warning system model f...

Python Programming - VI. Classes and Objects