Single logo
  • Courses
  • Articles
  • About
Join for freeJoin free
  1. Blog
  2. /
  3. full-stack-python-architect-fastapi-react-vibe-coding
  4. /
  5. Python OOP Basics: Classes, Objects, and Naming Conventions Explained

FULL STACK PYTHON ARCHITECT: FAST API + REACT + VIBE CODING
Web Development
0 views

Python OOP Basics: Classes, Objects, and Naming Conventions Explained

New to object-oriented programming in Python? This beginner-friendly guide breaks down classes, objects, and naming conventions with practical, real-world examples you can start using today.

A
Author
July 17, 2026

Why Object-Oriented Programming Matters in Python

If you've spent time writing Python scripts filled with functions and loose variables, you've probably hit a wall at some point. Your code works, but it's messy, hard to reuse, and even harder to scale. This is exactly the problem that Object-Oriented Programming (OOP) was designed to solve.

OOP is a programming paradigm that organizes code around objects rather than just functions and logic. Instead of thinking about your program as a series of steps, you start thinking about it as a collection of things — cars, students, animals, bank accounts — that have their own data and behavior. This shift in thinking is one of the most important transitions any Python developer makes, and it's foundational if you're planning to build modern applications with frameworks like FastAPI.

In this article, we'll break down the core building blocks of Python OOP: classes, objects, and the naming conventions that keep your code clean and professional. By the end, you'll have a solid foundation to start writing object-oriented Python code with confidence.

What Is a Class in Python?

Think of a class as a blueprint. It doesn't do anything on its own — it simply defines what something should look like and what it should be able to do. A class describes the structure (data) and behavior (methods) that its objects will have.

Here's a simple example using a real-world concept — a car:

class Car:
    def __init__(self, make, model, year):
        self.make = make
        self.model = model
        self.year = year

    def start_engine(self):
        return f"{self.make} {self.model}'s engine is starting."

In this example, Car is the class. The __init__ method is a special method (often called a constructor) that runs automatically whenever a new car object is created. It sets up the initial data — in this case, the make, model, and year of the car.

Breaking Down the Syntax

  • class Car: — This line declares a new class named Car. By convention, class names use PascalCase (more on that shortly).
  • def __init__(self, ...): — This is the constructor method. It's called automatically when you create a new object from the class.
  • self — This refers to the specific instance of the object being created or manipulated. It's how each object keeps track of its own data.
  • self.make = make — This assigns the value passed into the constructor to an attribute on the object itself.

What Is an Object?

If a class is the blueprint, an object is the actual thing built from that blueprint. You can create as many objects as you want from a single class, and each one can hold different data.

Using our Car class from above, here's how you'd create objects (also called instances):

car1 = Car("Toyota", "Corolla", 2022)
car2 = Car("Tesla", "Model 3", 2023)

Now you have two separate car objects. Each one has its own make, model, and year, even though they were both created from the same class. You can call methods on them too:

print(car1.start_engine())
# Output: Toyota Corolla's engine is starting.

This is the essence of OOP: define once, reuse many times. Instead of writing separate variables and functions for every car, you write one class and generate as many objects as you need.

Real-World Examples: Students and Animals

Cars are a great starting point, but OOP concepts click faster when you see them applied to different scenarios. Let's look at a simple Student class:

class Student:
    def __init__(self, name, grade):
        self.name = name
        self.grade = grade

    def introduce(self):
        return f"Hi, I'm {self.name} and I'm in grade {self.grade}."

Or an Animal class:

class Animal:
    def __init__(self, name, species):
        self.name = name
        self.species = species

    def make_sound(self):
        return f"{self.name} makes a sound."

Notice the pattern here: every class follows the same basic structure — a constructor to set up initial data, and methods that define what the object can do. Once this pattern becomes second nature, you'll start recognizing it everywhere in professional Python codebases, including in the models and schemas you'll build when working with FastAPI.

The Four Pillars of OOP (A Quick Preview)

While this article focuses on the basics, it's worth knowing that classes and objects are just the entry point into a much richer set of OOP principles:

  • Encapsulation — bundling data and methods together while controlling access to internal details.
  • Inheritance — allowing one class to inherit attributes and behavior from another.
  • Polymorphism — enabling different classes to be used interchangeably through a shared interface.
  • Abstraction — hiding complex implementation details behind simple, usable interfaces.

These concepts build directly on the foundation of classes and objects, and they're covered in depth later in the FULL STACK PYTHON ARCHITECT: FAST API + REACT + VIBE CODING course, where you'll apply them to real-world systems like online banking platforms and employee management tools.

Python Naming Conventions You Should Know

Writing OOP code isn't just about making it work — it's about making it readable and professional. Python has well-established naming conventions (largely defined in PEP 8) that every developer should follow.

Class Names: PascalCase

Class names should use PascalCase, meaning each word starts with a capital letter and there are no underscores:

  • Car
  • StudentRecord
  • BankAccount

Variables and Methods: snake_case

Variable names, function names, and method names should use snake_case — all lowercase with underscores separating words:

  • student_name
  • calculate_average()
  • start_engine()

Constants: UPPER_CASE

Constants — values that shouldn't change — are typically written in all uppercase with underscores:

  • MAX_SPEED
  • DEFAULT_GRADE

Private and Protected Attributes

Python also uses naming conventions to signal the intended visibility of attributes:

  • self.name — a public attribute, accessible from anywhere.
  • self._name — a protected attribute, meant for internal use (by convention, not enforced).
  • self.__name — a private attribute, which triggers Python's name mangling to discourage direct access.

These conventions don't just make your code prettier — they communicate intent to other developers (and to your future self) about how each piece of code should be used.

Putting It All Together

Let's combine everything we've covered into one cohesive example:

class Student:
    def __init__(self, name, score):
        self.name = name
        self.score = score

    def get_letter_grade(self):
        if self.score >= 90:
            return "A"
        elif self.score >= 80:
            return "B"
        else:
            return "F"

student1 = Student("Maria", 92)
print(f"{student1.name} received a {student1.get_letter_grade()}")

This small example already demonstrates a class acting as a blueprint, an object being instantiated, and a method encapsulating logic — all following proper Python naming conventions. This is precisely the kind of pattern used later in the course when building a full student grading system with class averages, report generation, and clean F-string formatting.

Where to Go From Here

Understanding classes, objects, and naming conventions is the first real step toward writing scalable, professional Python code. Once these basics feel natural, you'll be ready to explore more advanced OOP concepts — inheritance, polymorphism, composition, abstract classes, dataclasses, and special methods — all of which are covered in detail in the FULL STACK PYTHON ARCHITECT: FAST API + REACT + VIBE CODING course.

This course walks you through these concepts using real-world systems like banking platforms and employee management tools, so you're not just learning theory — you're learning how professional Python developers actually structure applications before building them out with FastAPI and React.

Featured Video

[Course video embed: PYTHON: OOP Introduction, Classes, Objects and Naming Conventions]

Key Takeaways

  • A class is a blueprint that defines the structure and behavior of objects.
  • An object is a specific instance created from a class, with its own data.
  • Python naming conventions — PascalCase for classes, snake_case for variables and methods, and UPPER_CASE for constants — keep your code clean and professional.
  • Underscore prefixes (_protected, __private) signal intended access levels for attributes.
  • Mastering classes and objects is the foundation for more advanced OOP concepts like inheritance, polymorphism, and composition.

If you're ready to go beyond the basics and start applying these principles to real-world applications, the full course dives deeper into advanced Python OOP patterns and shows you how to bring them into modern full stack development with FastAPI and React.

Tags:
python oop basics
python classes and objects
python naming conventions
object oriented programming python
Share Article

Back to All Articles

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.