为什么建议在 Ubuntu 的文本编辑器中使用 4 个空格而不是制表符?

Why is it recommended to use 4 spaces instead of tab in Ubuntu's Text Editor?

当我使用标签时,我收到

TabError: inconsistent use of tabs and spaces in indentation

然而,当我用 4 个空格替换它时,问题就解决了。有人可以解释为什么制表符和 4 个空格在视觉上看起来相同时会出现错误。

Tabs 和 spaces 是两个不同的字符,在屏幕上呈现相同。制表符对于制表符的宽度没有约定,它可能占用宽度 8,4 2 并且它也是可配置的。

Python 期望所有行中的缩进与第一行相同,无论是 1 space、4 spaces 还是 1 个制表符等。制表符的使用获胜'给你报错,不同行不一致会。

选项卡的列数可能会有所不同,具体取决于您的环境,但 space 始终是一列。

建议使用 spaces,尤其是在 python 编程语言中,以避免编辑器之间的错误。

Python 3 disallows mixing the use of tabs and spaces for indentation.

Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.

您还应该检查 pep8