searching strings using variables

Xavier Combelle xavier_combelle at yahoo.fr
Tue Jun 15 06:01:38 EDT 2004


It appears that giving the folowing list:
> mylist = [ 5 , 6 , 16 , 17 , 18 , 19 , 20 , 21 ]
> # my variable I want to search with...
and the folowwing variable
> myvar = '16'
the simple way to find the var in the list is
> mylist.index('myvar')
but that fail:

It seems that it's a problems of quotes:
doing that seems work better:

mylist = [ 5 , 6 , 16 , 17 , 18 , 19 , 20 , 21 ]
# my variable I want to search with...
myvar = 16
print mylist.index(myvar)

I'm not very experimented in python,
but, it seems that in python, use quote just to write literal
strings. you can't find a string in a list of int.




More information about the Python-list mailing list