5

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'
2
  • 3
    Please read pep-8 on how to format your python code properly. Commented Jun 25, 2012 at 8:32
  • thanks I have gone through a load of python tutorials and regular look up it on the documentation python Commented Jun 25, 2012 at 14:05

4 Answers 4

16

You've written it yourself almost correctly, just instead of -

if a is in b:

it should be -

if a in b:
Sign up to request clarification or add additional context in comments.

Comments

6

condition should be

if a in b:
    print 'enter in code thats wanted'

Comments

1
  • 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'

Comments

0

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')

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.