是否有任何方法可以使以下if语句更加优雅,而无需重复“ and”条件?抱歉,我是新手。
a = ' 10 20 30 40 50 '
print(a)
if '10' and '20' and '30' and '40' and '50' not in a :
print('something is wrong')
else:
print('This is correct')
谢谢
答案 0 :(得分:0)
尝试此尺寸。应该检查所有在a_string中的匹配字符串,如果不是,则打印“出问题了”。
a_string = "10 20 30 40 50"
matches = ["10", "20", "30", "40", "50"]
if not all(x in a_string for x in matches):
print('something is wrong')
else:
print('This is correct')