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>What it is saying is that <code>i</code> is an int. You are testing whether <code>i</code> is in <code>steps</code> which is a string. The mostly likely thing I think you are trying to do is get the <code>ith</code> character of the <code>steps</code> in which case you should use <code>if steps[i] == 'u':</code></p>

python if-statement