how to check variable against 2 possible values python
<p>I have a variable s which contains a one letter string</p>

<pre><code>s = 'a'
</code></pre>

<p>Depending on the value of that variable, I want to return different things. So far I am doing something along the lines of this:</p>

<pre><code>if s == 'a' or s == 'b':
   return 1
elif s == 'c' or s == 'd':
   return 2
else: 
   return 3
</code></pre>

<p>Is there a better way to write this? a more pythonic way? Or is this the most efficient?</p>

<p>Previously, I incorrectly had something like this:</p>

<pre><code>if s == 'a' or 'b':
   ...
</code></pre>

<p>Obviously that doesn't work and was pretty dumb of me. </p>

<p>I know of conditional assignment and have tried this:</p>

<pre><code>return 1 if s == 'a' or s == 'b' ...
</code></pre>

<p>I guess my question is specifically to is there a way you can compare a variable to two values without having to type 'something == something OR something == something'</p>
