Python - TypeError: unsupported operand type(s) for |: 'str' and 'str'
Python - TypeError: unsupported operand type(s) for |: 'str' and 'str'
我正在尝试编写如下 elif 条件:
if(type = a):
do this
elif(type=b|c):
do this
else:
do this
我收到以下语句的错误
elif(type=b|c)
错误:
TypeError: unsupported operand type(s) for |: 'str' and 'str'
任何人都可以建议我哪里出错了。谢谢
这不是语法。
elif(type == b or type == c):
或:
elif(type in [b, c]):
你的意思是(阅读评论):
if(type == a):
do this
elif type in {b,c}: # i use `set` because it's the fastest # Also can do `type==b or type==c`
do this
else:
do this
使用这个:
if(type == a):
do this
elif (type == b OR type == c):
do this
else:
do this
我正在尝试编写如下 elif 条件:
if(type = a):
do this
elif(type=b|c):
do this
else:
do this
我收到以下语句的错误
elif(type=b|c)
错误:
TypeError: unsupported operand type(s) for |: 'str' and 'str'
任何人都可以建议我哪里出错了。谢谢
这不是语法。
elif(type == b or type == c):
或:
elif(type in [b, c]):
你的意思是(阅读评论):
if(type == a):
do this
elif type in {b,c}: # i use `set` because it's the fastest # Also can do `type==b or type==c`
do this
else:
do this
使用这个:
if(type == a):
do this
elif (type == b OR type == c):
do this
else:
do this