Nov 10, 2013 18:30
# -*- coding:utf8 -*-
class GetResult:
result=[]
def add(self,x,y):
z= x+y
self.result.append(z)
rs=GetResult()
rs.add(1,2) #the result is [3]
print rs.result
rs.add(3,4)#the result is [7] #what i want the is [4]
print rs.result
Leave a comment
Comments 3
rs.result[-1] - rs.result[-2]
seems like most obvious.
WTF are you trying to do? I thought you were an anti-Dutch bigot anyway.
Reply
Reply
... result = []
... def add(self, x, y):
... z = x + y
... self.result.append(z)
...
>>> rs=GetResult()
>>> rs.result
[]
>>> rs.add(1,2)
>>> rs.result
[3]
>>> rs.add(3,4)
>>> rs.result
[3, 7]
>>>
Reply
Leave a comment