The code is:
print("Hello world\n\tHello world")
The result is:
Output:
Hello world
Hello world
but I want this \t result
Output:
Hello world
Hello world
I found the answer in another forum, use
print("Hello world\n\tHello world".expandtabs(4))
I think this is Python default.So,How to change this defualt setting.
I don't think it is a python setting. The call to print sends tab characters to the output stream. If the console prints 8 spaces when it receives a tab character, it doesn't have anything to do with python, unless you are running the code in a python IDE such as Idle. In my bash terminal, if I write a C program that prints the same output, it also inserts 8 spaces.
Same problem with bash's echo command
Output:
λ echo -e 'foo\n\tbar'
foo
bar
Edit: Actually, I've found a solution for the linux terminal
here. It suffices to type
tabs -4
to change the terminal's setting. For example
Output:
λ tabs -4
λ echo -e 'foo\n\tbar'
foo
bar
λ python3 -c "print('foo\n\tbar')"
foo
bar
It Worked!