Pythondex

Tutorial

Classes and Objects in Python

In Python, a class is like a design or blueprint, and an object is something made from that blueprint.

For example, think of a class as a design for a dog. It describes what every dog should have — like a name and a color. But it doesn’t create an actual dog yet.

When we make an actual dog using that design, that is an object.

Creating a Class

You can create a class in Python using the class keyword.

Here, we made a class called Dog that has two pieces of information: name and color.

Creating an Object

Now we can make an object from this class by writing the class name followed by parentheses ().

What You Learned

  • A class is like a design or blueprint for something.
  • An object is something made using that blueprint.
  • You can access data inside an object using . (dot) notation, like my_dog.name.

In the next tutorial, you’ll learn how to make classes more flexible using the special __init__() method.