I'm practicing format fuction and when I use this code with \t in it, the first 9 output did not have any big space `
import random
lst = [random.randint(1,100) for i in range(51)]
for index, val in enumerate(lst):
print(f'{index=}\t{val=}')
`
It works with \n but not \t, I don't know why. Can anyone explain it?
CodePudding user response:
It's just the terminal following tab convention(4 spaces into consideration). So add spaces before and after \t
.
CodePudding user response:
All results has \t
Run your code with python yourcode.py | cat -T
This is the results. ^I
is the tab.
$ python yourcode.py | cat -T
index=0^Ival=14
index=1^Ival=46
index=2^Ival=87
index=3^Ival=83
index=4^Ival=28
index=5^Ival=77
index=6^Ival=34
index=7^Ival=66
index=8^Ival=64
index=9^Ival=80
index=10^Ival=28
index=11^Ival=21
index=12^Ival=64
index=13^Ival=79
index=14^Ival=92
index=15^Ival=67
index=16^Ival=69
index=17^Ival=50
Man page of cat
says
-T, --show-tabs display TAB characters as ^I
You may change the length of TAB. Check this article