Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

OOP Basics – Classes | Python Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Python Fundamentals

Lesson 25 of 55

·Python

OOP Basics – Classes

20 minutes

Course progress45%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Define a class with `class ClassName:`.
  • `__init__(self, ...)` initializes instance attributes.
  • Methods receive the instance as the first argument (`self`).
  • Create an instance with `obj = ClassName(args)`.

OOP Basics – Classes

Object‑oriented programming groups data (attributes) and behavior (methods) into classes. Instances of a class are called objects.

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

    def greet(self):
        return f'Hi, I\'m {self.name} and I\'m {self.age} years old.'

bob = Person('Bob', 28)
print(bob.greet())

The __init__ method is the constructor; it runs automatically when you create a new object.

Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Python FundamentalsBrowse activities
Previous lessonRegular ExpressionsContinue to lesson 26OOP – InheritanceBack to Python Fundamentals curriculum