Learn Python — Read indentation when a lesson wraps onto a narrow screen
Reading and text size · Education
APK Mosaic · Edition date
Start with a tiny harmless program
Write a two-line example on paper: an if statement and an indented print statement beneath it. In a lesson or practice editor, inspect where a long line wraps. Can you distinguish a visual continuation from a new line that starts a new statement? Line numbers, indentation guides and a horizontal scroll area can each answer part of that question. Try at the text size you normally use.
Make the indentation difference visible
Compare an indented print with a second print outside the conditional. Use simple words as the output so the result is easy to recognize. If you use speech to read code, check how your chosen punctuation and indentation settings announce these lines. A lesson that displays the correct output may still leave the source difficult to navigate. Keep the sample small enough to locate the difference yourself.
Worked example
An indented statement wraps onto a third visual line, but the editor shows only two line numbers. Has a new Python statement begun?
The line-number gutter suggests a visual wrap. Inspect the source, including its indentation and punctuation, before interpreting the third visual line as another statement. Enlarge the editor or shorten the sample string and compare the logical line numbers again.
What to look for
Find the first nonspace character on each line.
Separate the continuation of a long string from a new statement.
Return from the output panel to the same line of code.