FUNCTIONS&OOP
FUNCTIONS&OOP
CLASS MEMBERS
● Class members are declarations made inside
the body of the class.
The following are class members:
○ Fields
■ Also referred to as attributes.
SET ■ These are data used by the class. They are
- A set is a collection which is unordered and variables
unindexed. In Python, sets are declared inside the class body.
written with curly brackets. ○ Methods
fruits= {"apple", "banana", "cherry"} ■ Also referred to as the behavior(s).
print(fruits) ■ These are program statements grouped
together to perform a specific function.
LIST,TUPLE,SET AND DICTIONARY
1. List is a collection which is ordered and CREATING AN OBJECT
changeable. Allows duplicate members. - Since classes are templates, they provide the
benefit of reusability.
2. Tuple is a collection which is ordered and - A class can be used over and over to create
unchangeable. Allows duplicate members. many objects.
- An object created out of a class will contain
the same variables that the class has. However,
3. Set is a collection which is unordered and the values of the variables are specific to the
unindexed. No duplicate members. object created.
- Creating an object out of a class is called class
4. Dictionary is a collection which is ordered* instantiation.
and changeable. No duplicate members.
to invoke the method, then the version in the
parent class will be executed, but if an object
of the subclass is used to invoke the method,
The __init__ function then the version in the child class will be
- The __init__() function is called automatically executed. In other words, it is the type of the
every time the class is object being referred to (not the type of the
being used to create a new object. reference variable) that determines which
Constructor in other programming. version of an overridden method will be
- "__init__" is a reserved method in python executed.
classes. It is known as a constructor in object
oriented concepts. This method called when an
object is created from the class and it allow the
class to initialize the attributes of a class.
INHERITANCE IN PYTHON
- In object-oriented programming (OOP),
inheritance is a mechanism that allows a class
to inherit properties and behaviours from
another class. It is a fundamental concept in
OOP that promotes code reuse and establishes
relationships between classes.
INHERITANCE
- Inheritance in OOP’s is based on a hierarchical
relationship between classes, where a derived
class (also known as a subclass or child class)
inherits the characteristics of a base class (also
known as a superclass or parent class). The
derived class extends the functionality of the
base class by adding new features or
overriding existing ones.
METHOD OVERRIDING
- Method overriding, in object-oriented
programming, is a language feature that allows
a subclass or child class to provide a specific
implementation of a method that is already
provided by one of its superclasses or parent
classes.