0% found this document useful (0 votes)
2 views

Python OOP Terminology

The document explains key Object-Oriented Programming (OOP) concepts in Python, including classes, objects, instantiation, methods, and encapsulation. It provides definitions and examples for each concept, such as class attributes, instance attributes, and method overloading. Additionally, it covers inheritance, demonstrating how one class can inherit characteristics from another.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python OOP Terminology

The document explains key Object-Oriented Programming (OOP) concepts in Python, including classes, objects, instantiation, methods, and encapsulation. It provides definitions and examples for each concept, such as class attributes, instance attributes, and method overloading. Additionally, it covers inheritance, demonstrating how one class can inherit characteristics from another.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

OOP Concept in Python

Description Example

Class A blueprint to create objects. It defines the data (attributes) and functionality (
class Dog:
methods) of the objects. You can access both attributes and methods via the dot
notation. # class attribute

is_hairy = True
Object A piece of encapsulated data with functionality in your Python program that is # constructor
(=instance) built according to a class definition. Often, an object corresponds to a thing in the
def __init__(self, name):
real world. An example is the object "Obama" that is created according to the class
definition "Person". An object consists of an arbitrary number of attributes and # instance attribute
methods, encapsulated within a single unit. self.name = name

Instantiation
The process of creating an object of a class. This is done with the constructor # method
method __init__(self, …). def bark(self):

Method print("Wuff")
A subset of the overall functionality of an object. The method is defined similarly
bello = Dog("bello")
to a function (using the keyword "def") in the class definition. An object can have
paris = Dog("paris")
an arbitrary number of methods.
print(bello.name)
Self "bello"
The first argument when defining any method is always the self argument. print(paris.name)
"paris"
This argument specifies the instance on which you call the method.
self gives the Python interpreter the information about the concrete instance.
To define a method, you use self to modify the instance attributes. But to
class Cat:
call an instance method, you do not need to specify self.

Encapsulation # method overloading


Binding together data and functionality that manipulates the data.
def miau(self, times=1):
Attribute print("miau " * times)
A variable defined for a class (class attribute) or for an object (instance attribute). You use
attributes to package data into enclosed units (class or instance). fifi = Cat()
fifi.miau()
"miau "
(=class variable, static variable, static attribute) A variable that is created statically in the fifi.miau(5)
Class attribute
class definition and that is shared by all class objects.
"miau miau miau miau miau "

Instance A variable that holds data that belongs only to a single instance. Other instances do not
attribute # Dynamic attribute
share this variable (in contrast to class attributes). In most cases, you create an instance
(=instance fifi.likes = "mice"
attribute x in the constructor when creating the instance itself using the self keywords (e.g.
variable) print(fifi.likes)
self.x = <val>).
"mice"

# Inheritance
Dynamic
An instance attribute that is defined dynamically during the execution of the program and
attribute class Persian_Cat(Cat):
that is not defined within any method. For example, you can simply add a new attribute
neew to any object o by calling o.neew = <val>. classification = "Persian"
mimi = Persian_Cat()
Method print(mimi.miau(3))
overloading You may want to define a method in a way so that there are multiple options to call
it. For example for class X, you define a method f(...) that can be called in three "miau miau miau "

ways: f(a), f(a,b), or f(a,b,c). To this end, you can define the method with default
print(mimi.classification)
parameters (e.g. f(a, b=None, c=None).

Inheritance Class A can inherit certain characteristics (like attributes or methods) from class B. For
example, the class "Dog" may inherit the attribute "number_of_legs" from the class
MD. Aliul Islam
"Animal". In this case, you would define the inherited class "Dog" as follows: "class 01518317509
Dog(Animal): ..."

You might also like