How do I write a "tab" in Python?


Question

Let's say I have a file. How do I write "hello" TAB "alex"?

1
96
5/10/2018 5:47:30 PM

Accepted Answer

This is the code:

f = open(filename, 'w')
f.write("hello\talex")

The \t inside the string is the escape sequence for the horizontal tabulation.

126
7/8/2019 10:49:10 PM

You can use \t in a string literal:

"hello\talex"


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon