The Python print function sends strings to standard output. Which standard output with these lines depends on the output device. The default interpretation of \t is to move to the next tab, which by convention represents the position of the character, which is the next multiple of 8 after the position in which \t occurs (counting the positions of characters to the left of 0).
For example, if I run:
babynames = [('kangaroo', 'joey'), ('fox', 'kit'), ('goose','gosling')] for x,y in babynames: print(x + '\t' + y)
I get:
kangaroo joey fox kit goose gosling
I got above in IDLE. kangaroo takes columns 0-7. \t is in column 8, so the next multiple is 8 (next tab) after the tab is in column 16, which is really where you see joey . On the next two lines, the next tab stop after the first word is in column 8. This shows that (at least in the IDLE shell) Python uses real tabs.
Tabs in this sense are somewhat annoying. They can only be used to align variable-length string data with a specific dose of annoying difficulty. As others have shown, the solution is to not use tabs, but use format instead
source share