4

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'
Sam
  • 7,252
  • 16
  • 46
  • 65
fanjojo
  • 99
  • 1
  • 1
  • 10
  • 3
    Please read [pep-8](http://www.python.org/dev/peps/pep-0008/) on how to format your python code properly. – georg Jun 25 '12 at 08:32
  • thanks I have gone through a load of python tutorials and regular look up it on the documentation python – fanjojo Jun 25 '12 at 14:05

4 Answers4

16

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

if a is in b:

it should be -

if a in b:
theharshest
  • 7,767
  • 11
  • 41
  • 51
6

condition should be

if a in b:
    print 'enter in code thats wanted'
avasal
  • 14,350
  • 4
  • 31
  • 47
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'
Azer
  • 1,200
  • 13
  • 23
Tanmesh Shah
  • 67
  • 1
  • 3
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')