Creating a Class

How to create a class in python?

We'll cover the following...

Creating a class in Python is very easy. Here is a very simple example:

Press + to interact
# Python 2.x syntax
class Vehicle(object):
"""docstring"""
def __init__(self):
"""Constructor"""
pass

This class doesn’t do anything in particular, however it is a very good learning tool. For example, to create a class, we need to use Python’s class keyword, followed by the name of the class. In Python, convention says that the class name should have the first letter capitalized. Next we have an open parentheses followed by the word object ...