This "__height" and "__width" really confuse me. Could someone explain to me why these two variables are prefixed with two underscores? Will it be the same if one underscore is prefixed to these variables? What is the difference? Thanks a lot.
class Square:
def __init__(self, height="0", width="0"):
self.height = height
self.width = width
@property
def height(self):
return self.__height
@height.setter
def height(self, value):
if value.isdigit():
self.__height = value
else:
print("Please only enter numbers for height")
@property
def width(self):
return self.__width
@width.setter
def width(self, value):
if value.isdigit():
self.__width = value
else:
print("Please only enter numbers for width")
def getArea(self):
return int(self.__width) * int(self.__height)
def main():
aSquare = Square()
height = input("Enter height : ")
width = input("Enter width : ")
aSquare.height = height
aSquare.width = width
print("Height :", aSquare.height)
print("Width :", aSquare.width)
print("The Area is :", aSquare.getArea())
main()