+ 1
Python 80.2 Properties isEven - bound method print
It took me a lot of time to find out that i need to invoke the function call in this practice to solve it. I got a „bound method...“ message in every solution i came up with instead of the value. Because in the code template the „()“ are missing I‘m curious if there‘s another variant without them. class Number: def __init__(self, num): self.value = num def isEven(self): return bool(self.value % 2 == 0) x = Number(int(input())) print(x.isEven()) <— had to add „()“ to the given code
4 Respuestas
+ 5
You can use @property decorator to wrap isEven function ,
@property
def isEven..
now you can use it just like a property without parenthesis.
+ 3
class Number:
def __init__(self, num):
self.value = num
#your code goes here
@property
def isEven(self):
if self.value % 2 == 0:
return True
else:
return False
x = Number(int(input()))
print(x.isEven)
+ 1
thank you, now the theory lesson makes more sense for me
0
In the beginning I thought we had to use getter or setter method to solve it...waste a lot of time and find out here that property method does the full job