这行不通:
if cond1 && cond2:
这行不通:
if cond1 && cond2:
当前回答
两个评论:
在Python中使用and和or进行逻辑操作。 缩进使用4个空格,而不是2个。您以后会感谢自己,因为您的代码看起来和其他人的代码几乎一样。更多细节请参见PEP 8。
其他回答
两个评论:
在Python中使用and和or进行逻辑操作。 缩进使用4个空格,而不是2个。您以后会感谢自己,因为您的代码看起来和其他人的代码几乎一样。更多细节请参见PEP 8。
Python使用and和or条件句。
i.e.
if foo == 'abc' and bar == 'bac' or zoo == '123':
# do something
一个&(不是两个&&)就足够了,或者就像上面的答案所说的,你可以用and。 我在熊猫身上也发现了这一点
cities['Is wide and has saint name'] = (cities['Population'] > 1000000)
& cities['City name'].apply(lambda name: name.startswith('San'))
如果我们将“&”替换为“and”,它将不起作用。
在条件句中使用and。我经常在导入Jupyter Notebook时使用这个:
def find_local_py_scripts():
import os # does not cost if already imported
for entry in os.scandir('.'):
# find files ending with .py
if entry.is_file() and entry.name.endswith(".py") :
print("- ", entry.name)
find_local_py_scripts()
- googlenet_custom_layers.py
- GoogLeNet_Inception_v1.py
用and代替&&。