what is oops in python

Hello everyone! 👋 welcome to the vbkinfo.xyz tutorial, In this tutorial, we’re going to learn what is oops in python — a powerful programming concept that helps you write cleaner, more organized, and reusable code. If you’ve ever been confused by words like class, object, inheritance, or polymorphism, don’t worry — I’ve got you! 

    Together, you and I will go through each concept step by step, using simple examples and clear explanations. By the end of this blog, you'll not only understand what OOPs is, but also how to actually use it in your Python programs.
So, let’s get started and make OOPs in Python super easy to understand!

if you want my last tutorial then please click here...
what is oops in python.
what is class in python
what sis object in python
what is abstraction in python

What is Class in Python

  • A class is a blueprint for creating objects.
  • You define a class using the class keyword.
  • It defines attributes (variables) and methods (functions) that the objects will have.
  • Objects are created from a class using constructor syntax like obj = ClassName().
  • Classes help in organizing code and implementing Object-Oriented Programming (OOP).
  • Classes support key OOP features like encapsulation, inheritance, and polymorphism.
  • class is a main building block of OOPS. in OOPS everything is resolved under the class and object. So, without classes, OOP doesn’t exist. You can think of a class as a blueprint, and objects as the real things built from that blueprint
  • You can create as many classes as you need in a single Python program.

lets see the below Example to understand clearly,


class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def greet(self):
        print(f"Hello, my name is {self.name} and I am {self.age} years old.")


# Creating an object of the class
person1 = Person("Alice", 25)

# Calling the method
person1.greet()
--------------------------------------------
#output
Hello, my name is Alice and I am 25 years old.


#explaination of the above program

1)here class name is Person

2)def __init__(self, name, age):
  
def → (it is an inbuild function in python)This means you're defining a function (or method). it is an inbuild

__init__ → This is a special built-in method in Python called a constructor. It runs automatically when you create an object from the class. (we will learn more about constructor in upcoming tutorials)

self → Refers to the current object (like "this" in other languages).

name and age → These are parameters that you pass when creating the object. They help to set the initial values (attributes) of that object.

3) self.name = name
    self.age = age

self.name and self.age are attributes( means variable name) of the object (i.e., data that belongs to the object).

name and age are parameters that come from outside when you create the object.

The = sign is assigning the values from the parameters to the object’s attributes.

4) def greet(self):
This line defines a method inside a class. A method is just a function that belongs to a class.

def → Keyword to define a function.
greet → The name of the method (you can choose any name).
(self) → Refers to the current object. It's required in all class methods to access the object’s data (like name, age, etc.).


Hope you are understand what is class clearly in the subpoint of what is oops in python.


what is Object in Python

  • An object is an instance of a class.
  • It represents a real-world entity with attributes (data/ variables) and methods (functions).
  • Objects store actual values for the variables defined in the class.
  • You create an object by calling the class like a function (e.g., obj = ClassName()).
  • Each object has its own unique data but shares the class’s structure.
  • Objects allow you to use and manipulate the data and behavior defined in the class.

lets check the below Object Example to understand clearly,

here we refer the Dog Example

class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
def bark(self):
print(f”{self.name} says Woof!”)

#Creating objects (instances) of the Dog class
dog1 = Dog(“Buddy”, “Golden Retriever”)
dog2 = Dog(“Max”, “Beagle”)

#Calling methods using the objects

dog1.bark() # Output: Buddy says Woof!
dog2.bark() # Output: Max says Woof!

#explaination of the above program

here dog1,dog2,dog3…. are the objects of this class
we can create the n number of the object.

dog1 = Dog(“Buddy”, “Golden Retriever”)
— Here Dog is a main class and dog1 are the object
and we passing the parameter to this Dog object

— we can pass different parameter in different object of dog

— try yourself
in the barks method try to add the {self.breed} and check the output.
also you can create the different method in this program and call the methods.

Hope you will be understand the object concept in what is oops in python tutorial.

What is Abstraction in Python

  • In Python OOPs , Abstraction is one of the pillar.
  • Abstraction means hiding the internal details and showing only the essential features.
  • It helps to simplify complex systems by breaking them into smaller, understandable parts.
  • In Python, abstraction is implemented using abstract classes and interfaces (via the abc module).You can define abstract methods that must be implemented in child classes.
  • It promotes code reusability, security, and clean design.It lets the user interact with objects without knowing their internal code.

Real World Example of Abstraction

Real-World Example 1: Coffee Machine
🔹 As a User:
You press a button → Coffee comes out.

🔹 What’s hidden from you (Abstracted)?
-> Heating water
-> Pumping pressure
-> Grinding beans
->Mixing ingredients

Here, You don’t see or control any of that. You only use the button to get the result.
That’s abstraction — hiding the complex internal details and showing only what’s needed.

🚗 Real-World Example 2: Car
🔹 As a Driver:
You use the steering wheel, accelerator, brake, etc.

🔹 What’s hidden (Abstracted)?
–> How the engine works
–> Fuel injection system
–>Gear mechanisms
–>Brake fluid pressure
–> Electrical wiring

You just drive the car. You don’t need to understand the inner mechanics.
That’s abstraction — you get a simple interface to a complex system.

Example of abstraction with coding

Code Explanation:

from abc import ABC, abstractmethod
—>This line brings in special tools from Python to create abstract classes, which are like templates for other classes.


class CoffeeMachine(ABC):
—> CoffeeMachine is an abstract class, which means you can’t create objects directly from it.
—>It serves as a blueprint for other classes to follow.

@abstractmethod
def make_coffee(self):
pass

—> This is an abstract method. It’s like saying:
“Any class that inherits from CoffeeMachine must have its own version of make_coffee().”
pass means there’s no code here yet.

def start_machine(self):
print(“Starting the coffee machine…”)

—>This method has real code.Even though CoffeeMachine is abstract, its concrete methods can still be used by child classes.

class MyCoffeeMachine(CoffeeMachine):
—> MyCoffeeMachineinherits from CoffeeMachine.Since CoffeeMachine has an abstract method, this child must implement it.

def make_coffee(self):
print(“Grinding beans…”)
print(“Boiling water…”)
print(“Brewing coffee…”)
print(“Your coffee is ready! ☕”)

—>This is the actual functionality for making coffee.Now this class is complete and can be used to create objects.

machine = MyCoffeeMachine()
—> This creates an object (or instance) of the MyCoffeeMachine class.

machine.start_machine()
—> This runs the normal method from the abstract class.

machine.make_coffee()
—> This runs the custom make_coffee() method from the child class.

this is the explanation of the Abstraction class ie the coffe machine,
Remember:
->Abstract classes can’t be used directly.
->They force child classes to provide certain methods.
->This is useful when you want to ensure every machine or class follows the same structure.

if you want to learn more about Abstraction then click here…

Summary:

In this tutorial, we explored the basics of Object-Oriented Programming (OOP) in Python or what is oops in python, focusing on classes, objects, and the concept of abstraction using abstract classes and methods. This gave us a solid foundation in understanding how to structure and organize code effectively using OOP principles. In the next tutorial, we will dive deeper into the remaining core concepts of OOP—polymorphism, inheritance, and encapsulation—to complete our understanding of the four fundamental pillars of object-oriented programming in Python

Comments

One response to “what is oops in python”

  1. […]     Hello, and welcome to VBKinfo.xyz! In this tutorial, we’re going to dive deep into inheritance in Python, which is a fundamental concept of Object-Oriented Programming (OOP). By understanding inheritance, developers can create new classes from existing ones, thereby making their code more modular, reusable, and maintainable.    Furthermore, this guide is designed to help you not only grasp the theory behind Python inheritance but also see working examples of all its types, including single, multiple, multilevel, hierarchical, and hybrid inheritance. Whether you are a newcomer to Python or simply looking to reinforce your OOP knowledge from previous tutorials, this tutorial will guide you step by step. In addition, you will learn how to practice and implement these techniques effectively in real-world Python projects, ensuring that your understanding is both practical and thorough. for previous tutorial click here.. […]

Leave a Reply

Your email address will not be published. Required fields are marked *