I am trying to combine some class methods or apply init value on itself without success.
class numOper:
def __init__(self, x):
self.x = x
def multiply(self, x):
self.x *= x
def add(self, x):
self.x += x
a = numOper(5)
print(a.x) # 5
a.multiply(3)
print(a.x) # 15
a.add(7)
print(a.x) # 22
a = numOper(5) # x = 5
a.multiply(3).add(7) # Error; trying multiply and then add to result
print(a.x)
a = numOper(5) # x = 5
a.multiply(a) # Error; trying to multiply by itself
These result in
AttributeError: 'NoneType' object has no attribute 'multiply'
AttributeError: 'NoneType' object has no attribute 'add'
Is there any way to do these? Or investigate?
In procedural python, this seems to works.
a = 5
def addf(a):
a += a
return a
addf(a)
or
a = 5
def addf(a):
a += a
return a
def double(a):
a *= 2
return a
double(addf(a))