python3 exception invalid syntax error
<p>I recently started learning python3, and I am trying to write an exception. 
I have this line, which is a list of words. 
I want to match the word create to the list, sometimes it's there sometimes its not. When it's not there I get this error:</p>

<pre><code>Traceback (most recent call last):
File "sub_process.py", line 17, in &lt;module&gt;
if (line.index("create")):
ValueError: 'create' is not in list
</code></pre>

<p>and I am fine with that. This is expected. So I thought if I wrote an exception to it the script could just continue on and keep doing stuff. So I an exception below and all its suppose to do is nothing. Catch the error and continue on.</p>

<pre><code>line = line.split()

if line.index("create"):
    print("basd");
except ValueError:
    print("123");
</code></pre>

<p>But everytime i try to compile this I get syntax error at "except" and I am not sure why. It looks perfectly normal compared against all the tutorials that I could find.</p>

<p>You need to add <code>try</code> before the <code>if</code> statement:</p>

<pre><code>line = line.split()
try: # added 'try'
    if line.index("create"):
        print("basd");
except ValueError:
    print("123");
</code></pre>

<p>Also note, you don't need the semicolons at the end of statements, and it is generally frowned upon when they are used in that way.</p>

<p>As an alterintave to @Rosemans solution, you can do that all on one line:</p>

<pre><code>print('basd') if "create" in line else print("123")
</code></pre>

python exception