I want to be able to enter a value and check if it is in a list and if it is then in the list run a the rest of the program wanted.
a=input('enter value')
b=(1,2,3,4)
c=(5,6,7,8,9)
if a is in b:
print 'enter in code thats wanted'
I want to be able to enter a value and check if it is in a list and if it is then in the list run a the rest of the program wanted.
a=input('enter value')
b=(1,2,3,4)
c=(5,6,7,8,9)
if a is in b:
print 'enter in code thats wanted'
You've written it yourself almost correctly, just instead of -
if a is in b:
it should be -
if a in b:
in operator: The ‘in’ operator is used to check if a value exists in a sequence or not. Evaluates to true if it finds a variable in the specified sequence and false otherwise.
‘is’ operator: Evaluates to true if the variables on either side of the operator point to the same object and false otherwise.
hence:
if a in b:
print 'enter in the code that\'s wanted'
It should be like this ↓
a=input('enter value')
b=(1,2,3,4)
c=(5,6,7,8,9)
if a in b:
print ('enter in code thats wanted')