转义字符\ t对空间的行为不同

时间:2022-05-06 20:44:24

Why do I see output only if I put space.

为什么只有放空间才能看到输出。

print "I love you %s" % "\tI'm tabbled in."
print "I love you %s" % " \tI'm tabbled in."

output

I love you  I'm tabbled in.
I love you      I'm tabbled in.

1 个解决方案

#1


Typically, \t (TAB) goes to the next tab stop - it is not a synonym for "n spaces".

通常,\ t(TAB)转到下一个制表位 - 它不是“n空格”的同义词。

 I love you XI'm tabbled in.
 I love you  XXXXI'm tabbled in.
 0---1---2---3---4---

The current terminal is configured with a tab stop size of 4 which is shown on the bottom. The "X" are the characters skipped by the tab.

当前终端配置有标签挡块尺寸4,显示在底部。 “X”是选项卡跳过的字符。

So the first line skips one character with the tab (it goes to tab stop #3) and the second line writes a space and then skips four characters (to get to tab stop #4).

因此第一行跳过一个带有选项卡的字符(它转到制表位#3),第二行写一个空格,然后跳过四个字符(转到制表位#4)。

#1


Typically, \t (TAB) goes to the next tab stop - it is not a synonym for "n spaces".

通常,\ t(TAB)转到下一个制表位 - 它不是“n空格”的同义词。

 I love you XI'm tabbled in.
 I love you  XXXXI'm tabbled in.
 0---1---2---3---4---

The current terminal is configured with a tab stop size of 4 which is shown on the bottom. The "X" are the characters skipped by the tab.

当前终端配置有标签挡块尺寸4,显示在底部。 “X”是选项卡跳过的字符。

So the first line skips one character with the tab (it goes to tab stop #3) and the second line writes a space and then skips four characters (to get to tab stop #4).

因此第一行跳过一个带有选项卡的字符(它转到制表位#3),第二行写一个空格,然后跳过四个字符(转到制表位#4)。