Tabs for indentation & Spaces for alignment in Python 3?

Ian Kelly ian.g.kelly at gmail.com
Fri Dec 5 13:30:43 EST 2014


On Fri, Dec 5, 2014 at 10:40 AM, Aahan Krish <krish at aahan.me> wrote:
> Q2. PEP 8 also reads, "Python 3 disallows mixing the use of tabs and
spaces for indentation."
>
> So, if I am using tabs for indentation and spaces for alignment, is it
still considered "mixing the use of tabs and spaces" in Python 3? (Please
see this example.)

No, you can mix tabs and spaces as long as you do so consistently within a
block, i.e. if one line is indented with <tab><sp><sp><tab> then the next
line in the same block had better start with that same exact sequence. The
difference is that Python 2 when trying to compare indentation will treat a
tab as equal to 8 spaces (or was it 4?) which can lead to situations where
the relative indentation of two lines looks one way to the programmer but
is lexed a different way by the interpreter. Python 3 resists the
temptation to guess in this situation and simply raises an error.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141205/01dac57c/attachment.html>


More information about the Python-list mailing list