syntax of "is" operator in python

Viewed 29
list = ['xy', 'yz', '=', '1', 'in', '>', 't']

for value in list:
   if value is '0' or '1':
      Zustand = value
      print("Zustand:", Zustand)

The if loop should check if the value of list is 0 or 1. Why does it print every value? I also tried the "==" operator.

1 Answers
if value is '0' or '1':

this is evaluated as

if (value is '0') or ('1'):

which is always true. try

if value is '0' or value is '1':
Related