相关疑难解决方法(0)

if语句在单行上进行多次逻辑比较

我想在Python中的逻辑条件做多重比较,但我不知道正确的方式圆了的andor.我有2个陈述.

声明1:

#if PAB is more than BAC and either PAB is less than PAC or PAC is more than BAC
if PAB > BAC and PAB< PAC or PAB > BAC and PAC>BAC: 
Run Code Online (Sandbox Code Playgroud)

声明2:

#if PAB is more than BAC and PAC is less than PAB or if PAB is less than BAC and PAC is less than BAC
if PAB >BAC and  PAC<PAB or PAB<BAC and  PAC<BAC
Run Code Online (Sandbox Code Playgroud)

是不是正确的两种方式去做呢?

谢谢.

python

8
推荐指数
1
解决办法
2万
查看次数

Python"in"和"=="混淆

print('a' in 'aa')
print('a' in 'aa' == True)
print(('a' in 'aa') == True)
print('a' in ('aa' == True))
Run Code Online (Sandbox Code Playgroud)

输出是

True
False
True
Traceback (most recent call last):
  File "main.py", line 6, in <module>
    print('a' in ('aa' == True))
TypeError: argument of type 'bool' is not iterable
Run Code Online (Sandbox Code Playgroud)

如果第2行既不是第3行也不是第4行,那么它是什么?怎么会变错?

python

5
推荐指数
1
解决办法
92
查看次数

标签 统计

python ×2