Python 'if' statement - if in [string] == 'string' -- Not working?
<p>I'm trying to find a letter in a giving string. Here's what I got:</p>

<pre><code> if i in steps == 'u':
    y -= pixels_per_move
elif i in [steps] == 'r':
    x -= pixels_per_move
</code></pre>

<p>steps is a randomly generated string consisting of u, d, r, l. 
So it's something like 'uuurlluddd'</p>

<p>So i'm just looking for those letters in 'steps' but with the code above I'm getting the error </p>

<p>TypeError: 'in ' requires string as left operand, not int</p>

<p>Which I don't understand because steps is not an int, and i've tried putting str() around it in multiple places but same error occurs. What am I doing wrong here?</p>

<p>You confuse the <code>for i in steps</code> with the <code>if</code> statement. Anyway, it should look something like this:</p>

<pre><code>for i in steps:
    if i == "u": #here i isn't a int but a string!
        y -= pixels_per_move
    elif i == "r":
        x -= pixels_per_move
</code></pre>

<p>You could add a <code>print</code> statement to print x and y (optional).</p>

python if-statement