Member-only story

Classes and OOP Concepts in Python

sneha.dev
The Pythoneers
Published in
4 min readDec 5, 2024

Object-Oriented Programming (OOP) is a programming paradigm that uses “objects” to represent data and methods. In Python, a class is a blueprint for creating objects, encapsulating data, and defining behaviors (methods). OOP principles help in organizing code in a modular, reusable, and scalable way.

Here are the core OOP concepts in Python:

1. Class

A class in Python is a blueprint for creating objects. It defines a set of attributes (variables) and methods (functions) that the objects created from the class will have. A class is like a template, and each object is an instance of that class.

Example of a Class:

class Dog:
# Constructor (__init__) to initialize object
def __init__(self, name, breed):
self.name = name # Attribute
self.breed = breed # Attribute

# Method to describe the dog
def bark(self):
return f"{self.name} is barking!"

# Creating objects (instances) of the Dog class
dog1 = Dog("Buddy", "Golden Retriever")
dog2 = Dog("Bella", "Labrador")

# Accessing attributes and calling methods
print(dog1.name) # Output: Buddy
print(dog2.breed) # Output: Labrador
print(dog1.bark()) # Output: Buddy is barking!

2. Object

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

The Pythoneers
The Pythoneers

Published in The Pythoneers

Your home for innovative tech stories about Python and its limitless possibilities. Discover, learn, and get inspired.

sneha.dev
sneha.dev

Written by sneha.dev

Software Engineer | Data Science | Technical Writer

Responses (1)

Write a response