accessor/mutator functions
mirandacascade at yahoo.com
mirandacascade at yahoo.com
Fri Feb 25 10:54:55 EST 2005
If the class had two attributes--x and y--would the code look like
something lik this:
class C(object):
def __init__(self):
self.__x = 0
self.__y = 0
def getx(self):
return self.__x
def setx(self, x):
if x < 0: x = 0
self.__x = x
def gety(self):
return self.__y
def sety(self, y):
if y < 0: y = 0
self.__y = y
x = property(getx, setx)
y = property(gety, sety)
?
Because if so, does the term 'lazy evaluation' refer to the fact that
instead of:
C().getx()
C().gety()
C().setx(10)
C().sety(10)
one would substitute:
C().x
C().y
C().x = 10
C().y = 10
?
More information about the Python-list
mailing list