How to Modify Properties On Class Objects in Python


In this example we will show how to modify properties on class objects in Python.

Source Code

class Sum:
    def __init__(self, a, b):
        self.a = a
        self.b = b

    def my_function(self):
        s = self.a + self.b
        print(s)

sum1 = Sum(2, 6)
print(sum1.a)
sum1.a = 10
print(sum1.a)

Output:

2
10
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments