Difference between "number% 2:" and "number% 2 == 0"?
3 answers
number % 2
is 0 (so False) if the number is
number % 2 == 0
True, the number is
The first returns a int
, where the second returns a bool
. Python right-hander lets you handle them the same way though.
+11
source to share
Simple. you can try in your terminal:
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> if 5%2:
... print "T"
...
T
>>> if 5%2 == 0:
... print "T"
...
>>>
1) if the condition is looking for an answer> 1.2
) In a) you are looking if the answer is> 1 in b) you are looking if the answer is == 0 (if so, as in all other language ==, it will return 1)
+1
source to share