Python simple program using class and object


In this program, you will learn how to create a simple program using class and object in Python.


self.x = x + 10

Example: How to create a simple program using class and object in Python

class Test:

    def change(self, x):
        self.x = x + 10

    def display(self):
        print("After value change:", self.x)


x = int(input("Enter a number:"))

obj = Test()
obj.change(x)
obj.display()

Output:

Enter a number:10
After value change: 20