Instance variable not changing

The instance variable 'x' is not changing as expected after assignment.

This is my code:

class Foo:
def __init__(self, x=0):
    self.x = x
    if self.x>=100:
        self.x = int(str(self.x)[-2:])
    elif self.x<0:
        self.x = -1

p = Foo()
print(p.x)
p.x = 125
print(p.x)
p.x = -945
print(p.x)

Expected:

0
25
-1

However I got this:

0
125
-945


#python

4 Likes1.75 GEEK