July 5, 2026

Code Snippet – How to Create a Class in Python

The code below shows how to create a class in Python. You can copy and modify freely for your personal use.

# ***************** HOW TO CREATE A CLASS IN PYTHON **************************
# Written by: Kindson The Genius
# Date: December 26th, 2018

class Student:

    # Class Variable
    studentCount = 0

    # Constructor
    def __init__(self, regno, firstname, lastname, course, email, level, gpa):
        self.regno = regno
        self.firstname = firstname
        self.lastname = lastname
        self.address = course
        self.email = email
        self.phone = level
        self.gpa = gpa

    # Member Function
    def display(self):
        print("Name: %s %s; Reg No. %s" %(self.firstname, self.lastname, self.regno))

# ******************************** END OF CLASS ****************************************

Listing 1.0: How to Create a Class in Python























kindsonthegenius

Kindson Munonye is a software engineer and technical author covering machine learning, statistics, REST APIs, Python, and software engineering. He publishes free tutorials on The Genius Blog and live classes on Alkademy.GitHub · LinkedIn · About · Alkademy

View all posts by kindsonthegenius →
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted