Member-only story
What is a Python Class — Beginners Guide
Learn the basics of Python classes with examples
Python is an object-oriented programming language. It means almost everything is an object. When becoming a Python developer, it’s crucial to learn what is a Python class and how to use it to create objects.
A Python class is a blueprint for creating objects:
class Person:
name = "Sofie"
A Python object is an instance of a class:
girl = Person()
An object is also known as an instance of a class. The process of creating objects from a class is called instantiation.
How to Create a Class in Python
Here is the basic syntax for defining a class in Python:
class ExampleClass:
# Add code here
And here is the syntax on how to instantiate objects from the class:
object = ExampleClass()
You can also use initializers in your class. Then it is possible to add unique values to the class objects upon creation