How to Create a Class in Python


In this example we will show how to create a class in Python.

Source Code

class MyClass:
    x = 123

    def my_function(self):
        return 'I love Python!'

print(MyClass)

Output:

<class '__main__.MyClass'>
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments