[ACCEPTED]-Check if string contains one value or another, syntax error?-if-statement
Accepted answer
Python's logical OR operator is called or
. There is no ||
.
if string == 'left' or string == 'right':
## ^^
BTW, in 4 Python this kind of test is usually written 3 as:
if string in ('left', 'right'):
## in Python ≥3.1, also possible with set literal
## if string in {'left', 'right'}:
Also note that str
is a built-in function in Python. You should 2 avoid naming a variable that clashes with 1 them.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.