I want to search if a list contains a string or not. The following code does not compile.
list= []
list.append("item1")
list.append("item2")
list.append("item3")
if 'item1' in list
print "yes"
else
print "no"
Error:
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/py_compile.py", line 117, in compile
raise py_exc
py_compile.PyCompileError: File "prog.py", line 6
if 'item1' in command
^
SyntaxError: invalid syntax
listis a builtin, you should not use it as a variable name. preferlstorseqinstead, for simple options (though you should usually be able to come up with something more descriptive)