Trying to understand private/public attributes for a class I started to play with @property. I don't get why when I define a class like this:
class Number(object):
@property
def num1(self):
return self._num1
@num1.setter
def num1(self, i):
if i < 5:
raise ValueError("Small number!")
self._num1 = i
When I create an object using such class and set values for var num1like this:
def testNumber():
number = Number()
number.num1 = 22
number._num1=2
print number._num1
print number.num1
That will output 2 for num1 and _num1, avoiding the @property set for num1. Now if I set num1 with a lower value than 5 the exception is raised. How does this work for Pyhton? (no need to add that I'm new at Python)