Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.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中,逻辑`和`运算符如何处理整数?_Python - Fatal编程技术网

在Python中,逻辑`和`运算符如何处理整数?

在Python中,逻辑`和`运算符如何处理整数?,python,Python,所以,我在玩翻译,输入了以下内容: In [95]: 1 and 2 Out[95]: 2 In [96]: 1 and 5 Out[96]: 5 In [97]: 234324 and 2 Out[97]: 2 In [98]: 234324 and 22343243242 Out[98]: 22343243242L In [99]: 1 or 2 and 9 Out[99]: 1 起初我认为这与假值和真值有关,因为: In [101]: True + True Out[101]:

所以,我在玩翻译,输入了以下内容:

In [95]: 1 and 2
Out[95]: 2

In [96]: 1 and 5
Out[96]: 5

In [97]: 234324 and 2
Out[97]: 2

In [98]: 234324 and 22343243242
Out[98]: 22343243242L

In [99]: 1 or 2 and 9
Out[99]: 1
起初我认为这与假值和真值有关,因为:

In [101]: True + True
Out[101]: 2

In [102]: True * 5
Out[102]: 5
但这似乎并不相关,因为False总是0,从上面的试验来看,它似乎不是输出的最大值

老实说,我在这里看不到模式,在文档中也找不到任何东西(老实说,我真的不知道如何有效地查找它)

那么,你是怎么做的

int(x) [logical operation] int(y)

用Python工作

来自Python文档:

表达式
x和y
首先计算
x
;如果
x
为false,则其 返回值;否则,将计算
y
,并计算结果值 他回来了

这正是你的实验所显示的。所有
x
值均为真,因此返回
y


它适用于Python中的每一项,它不依赖于整数

not x   Returns True if x is False, False otherwise
x and y Returns x if x is False, y otherwise
x or y  Returns y if x is False, x otherwise
1为真,因此它将返回2

我发现不是x