A tab character is whitespace used for horizontal spacing. In Python strings, write it as the escape sequence \t; when printed, the terminal renders it as a tab. section 4.6 section 6.3.3
Keep these distinctions in mind:
- Inside a string, \t represents one tab character rather than the two visible characters backslash and t. section 4.6
- Interactive evaluation displays special characters explicitly, while print() sends them to the terminal for rendering. section 6.3.3
- Do not mix tabs and spaces for Python indentation: they may look aligned in an editor but map to different indentation levels. section 8.10
- Use spaces for Python indentation when possible; if tabs are required, use them consistently within a block. section 8.10
Visible value versus rendered output
The string 'a\n\tb' contains a newline followed by a tab. Evaluating it interactively shows the escapes, whereas print('a\n\tb') displays the characters as separate lines with horizontal spacing before b. section 6.3.3
'a\n\tb'
'a\n\tb'
print('a\n\tb')
a
b
Compare the explicit escape notation with the terminal rendering of the same string. section 6.3.3
