title: I'm getting an IndentationError. How do I fix it?
body: <p>I have a Python script:</p>
  <pre><code>if True:
      if False:
          print('foo')
     print('bar')
  </code></pre>
  <p>However, when I attempt to run my script, Python raises an <code>IndentationError</code>:</p>
  <pre class="lang-none prettyprint-override"><code>  File &quot;script.py&quot;, line 4
      print('bar')
                 ^
  IndentationError: unindent does not match any outer indentation level
  </code></pre>
  <p>I kept playing around with my program, and I was able to produce four errors in total:</p>
  <ul>
  <li><code>IndentationError: unexpected indent</code></li>
  <li><code>IndentationError: expected an indented block</code></li>
  <li><code>TabError: inconsistent use of tabs and spaces in indentation</code></li>
  <li><code>IndentationError: unindent does not match any outer indentation level</code></li>
  </ul>
  <p>What do these errors mean? What am I doing wrong? How can I fix my code?</p>
  <hr />
  <p><sub><strong>Note:</strong> This is an attempt at a <a href="https://meta.stackoverflow.com/questions/291992/what-is-a-canonical-question-answer-and-what-is-their-purpose">canonical question</a> because I see many similar posts every month. This is not a duplicate of existing questions about <a href="https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level">unindents</a> or <a href="https://stackoverflow.com/questions/1016814/what-to-do-with-unexpected-indent-in-python">unexpected indents</a> because they only deal with one type of indentation error each, and I'm looking to cover them all in one place.</sub></p>
  <p><sub>It's also possible to have <em>logically</em> incorrect indentation that <em>does not</em> cause an error message. One common form of this is attaching <code>else:</code> to a <code>for</code> or <code>while</code> loop rather than (as intended) the corresponding <code>if:</code>. See <a href="https://stackoverflow.com/questions/3295938">Else clause on Python while statement</a> if you need to close questions where OP did that.</sub></p>