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 = email = 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

Admin bar avatar


Kindson Munonye is currently completing his doctoral program in Software Engineering in Budapest University of Technology and Economics

View all posts by kindsonthegenius →

Leave a Reply

Your email address will not be published. Required fields are marked *