Python VBA-like left()
<p>I've been looking around but don't see anything similar to what I'm looking for.  Within a django site I want to add some code that looks at a values furthest left (or the first) character in a variable (which is populated by a DB query), and if it's a particular letter or number, do something with said variable.  How can I do this?</p>

<p>This checks if the first letter in <code>mystring</code> is <code>'a'</code> or <code>'b'</code>.</p>

<pre><code>if mystring[0] in ('a', 'b'):
    # whatever
</code></pre>

<p>Use slicing to test for longer substrings:</p>

<pre><code>if mystring[:3] in ('abc', 'def', '987'):
    # whatever
</code></pre>

<p>Alternatively you can use <code>str.startswith()</code>:</p>

<pre><code>if mystring.startswith(('SUBTOTAL', 'TOTAL')):
    # whatever
</code></pre>

python django