Difference between "or" and bitwise operator in Python -
this question has answer here:
- boolean operators vs bitwise operators 6 answers
i new python programming, , ran problem.
while(true): paneltype = input("enter type of panel[a, b, c, d]: ") if(paneltype.lower() != "a" | paneltype.lower() != "b" | paneltype.lower() != "c" | paneltype.lower() != "d"): logger.error("not valid input. try again") else: break
when use bitwise operator error: unsupported operand type(s) |: 'str' , 'str'
. however, once changed or operator, worked well.
could explain why occurred?
thanks
!=
has lower precedence |
tried calculating "a" | paneltype.lower()
makes no sense.
|
operator meant numbers, similar *
or +
, makes sense you'd calculate before making comparisons such >
or !=
. want or
in case, has lower precedence.
better yet:
if paneltype.lower() in ('a', 'b', 'c', 'd'):
Comments
Post a Comment