Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 与x27之间的差异;编号%2:';和';数字%2==0';?_Python_Python 3.x - Fatal编程技术网

Python 与x27之间的差异;编号%2:';和';数字%2==0';?

Python 与x27之间的差异;编号%2:';和';数字%2==0';?,python,python-3.x,Python,Python 3.x,我正在学习Python的布尔逻辑,以及如何缩短时间。标题中的两个表达是否相等?如果不是,它们之间有什么区别?如果数字为偶数,则数字%2为0(非常假) 数字%2==0为真,数字为偶数 第一个返回一个int,第二个返回一个bool。Python允许您以同样的方式处理它们。number%2 等于(缩写为) 编号%2!=0 因为1的计算结果为真,0的计算结果为假。这很简单。您可以在您的终端上尝试: Python 2.7.6 (default, Sep 9 2014, 15:04:36) [GCC 4

我正在学习Python的布尔逻辑,以及如何缩短时间。标题中的两个表达是否相等?如果不是,它们之间有什么区别?

如果数字为偶数,则数字%2为0(非常假)

数字%2==0
为真,数字为偶数


第一个返回一个
int
,第二个返回一个
bool
。Python允许您以同样的方式处理它们。

number%2

等于(缩写为)

编号%2!=0


因为1的计算结果为真,0的计算结果为假。这很简单。您可以在您的终端上尝试:

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) 如果条件查找答案>1。
2) 在a)中,如果答案大于1,则您正在查找
在b)中,您正在查找答案==0(如果在所有其他语言中都是这样==将返回1)

#Pro。今天学到了一些东西基本上
不是num%2
number%2==0
FirebladeDan相同。。。两者都计算为余数,并且都计算为True或False。本质上,如果有余数,它的计算结果为True。如果没有余数,则计算结果为False。如果5%2==True,您也可以执行
,如果4%2==False,您也可以执行