3 ms·
> If the last line started with 8 spaces, Python will not distinguish between the next line starting with 10 spaces and the next line starting with 50. Perhaps
by BeetleB 3y ago
> If the last line started with 8 spaces, Python will not distinguish between the next line starting with 10 spaces and the next line starting with 50.
Perhaps I misunderstood your comment, but this is quite wrong. If I have a block that's indented at 8 spaces, and the next line is 10 spaces, but should be in the same block, it will definitely throw an IndentationError.
- thaumasiotes 3y agoYes, you've misunderstood. If the last line started with 8 spaces, Python will see a difference between (the next line starting with 8 spaces), (the next line starting with 6 spaces), and (the next line starting with 10 spaces). Option 1 does nothing. Option 2 produces a DEDENT token. And option 3 produces an INDENT token. In the same scenario, Python does not distinguish between (the next line starting with 10 spaces), which produces an INDENT token, and (the next line starting with 50 spaces), which produces the same INDENT token. The amount of whitespace isn't relevant. All that matters is the comparison between one line and the previous line.