How to Use Class to Create Objects in Python


In this example we will show how to use the class to create objects in Python.

Source Code

class MyClass:
    x = 123

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

obj_1 = MyClass()
print(obj_1.x)

Output:

123
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments