看看这是否是比较python3中作为参数传入的字符串变量的最python方法。我的测试表明这是有效的,但是我不明白为什么
or
不起作用
and
威尔。这只是一个演示,tag变量是从命令行设置的。当我测试时
centos6, centos7, centos8
我击中了
else
而且工作如期。这是最好的方法吗?还是这错了?
tag = 'centos6'
if tag != 'centos6' and tag != 'centos7' \
and tag != 'centos8':
print('[--os %s] must be [--os centos6] or '
'[--os centos7] or [--os centos8]' % tag)
print('fail')
else:
print('good')