The 6 AI Engineering Patterns, come build with Greg live:Β Starts Jan 6th, 2025
Leverage
Glossary

Class

Create a Python class with properties and methods

A Python Class is an object that can hold information. It is a building block and cornerstone of the Python language. In fact, Python is an Object-Oriented Programming (OOP) language and classes are what make it so.

Classes are extremely useful for writing efficient clean code that is reusable. All of your favorite python libraries use classes to give you awesome functionality.

Within classes, you can hold properties (like class variables) and methods (class functions). You can also have class inheritance β€” child and parent classes, but this is a lesson for another time.

In the example below, I’m creating a Student class that has a name and age property. The class part is just the template. We don’t actually create a Student object until the last line…Bob.

class Student():
  def __init__(self, name, age):
    self.name = name
    self.age = age
    
student1 = Student("Bob", 21)

Note: You may hear the word object get used. The person using this means a single instantiated instance of a class. Instantiated means it has been created.

Let’s take a look at a python class code sample.

Link to code

On this page

No Headings