Python 80.2 Properties isEven - bound method print | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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

15th Feb 2021, 10:59 PM
Oliver Petters
Oliver Petters - avatar
4 Respostas
+ 5
You can use @property decorator to wrap isEven function , @property def isEven.. now you can use it just like a property without parenthesis.
15th Feb 2021, 11:19 PM
Abhay
Abhay - avatar
+ 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)
19th Nov 2021, 1:59 PM
Stefan Bartl
Stefan Bartl - avatar
+ 1
thank you, now the theory lesson makes more sense for me
15th Feb 2021, 11:48 PM
Oliver Petters
Oliver Petters - avatar
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
19th Sep 2021, 9:15 AM
Huan
Huan - avatar