CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Member-only story

What is a Python Class — Beginners Guide

Artturi Jalli
CodeX
Published in
5 min readJul 4, 2021

--

Photo by Marius Niveri on Unsplash

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

--

--

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Responses (2)