For those of you who don't know, oop stands for Object-Oriented Programming. Is python an oop, and why?
What is an OOP
Object-oriented programming (OOP) is a programming style distinguished by the identification of classes of objects that are inextricably linked with the methods (functions) with which they are associated. It also includes concepts such as attribute and method inheritance.
Why is python an OOP
- Class: A class is a collection of objects. Python allows users to declare classes by using the syntax below.
- Object: An Object is a subset of a Class. A class is similar to a blueprint, whereas an instance is a copy of the class that contains actual values.
Basically, if you have a class of people and the properties are gender and age. The objects would be each individual created.
I know its a lot to take in so lets break it down.
~ [class People] - Declares a class called People.
~[def __init__(self, s, a):] - Defines a function called __init__ which has three variables self, s, a. Lets understand __init___ . This function is strictly declared when an object is created from a class. The (self) is needed to access all the individual attributes of the object hence the [print(praise.gender)] if more object where declared, only the attributes assigned to praise would be declared.
- Methods: This is used to define the behaviors of an object
- Some of the other attributes of an oop present in python (which would be covered later) are: Inheritance, Encapsulation, Polymorphism and Data Abstraction.
« Python Print and Input | PIP »