Class

noun

say it: “klas” /klæs/

A blueprint for making objects that bundle data with the actions that go with it; one Dog class can make many dogs.

What is a class in Python?

A class is a blueprint for making objects that bundle data and the actions that go with it. One Dog class can make many dogs.

class Dog:
    def __init__(self, name):
        self.name = name

    def bark(self):
        print(f"{self.name} says woof!")

rex = Dog("Rex")
rex.bark()  # Rex says woof!

In a sentence

  • “The Product class gives every product a name, a price and a way to print itself.”
  • “rex = Dog("Rex") makes one object from the Dog class.”

Level: Journeyman · More Python terms at this level

Updated

In other subjects