Python Expand Tabs Length Calculation

前端 未结 2 1057
别跟我提以往
别跟我提以往 2020-12-06 07:45

I\'m confused by how the length of a string is calculated when expandtabs is used. I thought expandtabs replaces tabs with the appropriate number of spaces (with the default

2条回答
  •  情书的邮戳
    2020-12-06 08:47

    Like when you are entering tabs in a text-editor, the tab character increases the length to the next multiple of 8.

    So:

    • '\t' by itself is 8, obviously.
    • '\t\t' is 16.
    • 'abc\tabc' starts at 3 characters, then a tab pushes it up to 8, and then the last 'abc' pushes it from 8 to 11...
    • 'abc\tabc\tabc' likewise starts at 3, tab bumps it to 8, another 'abc' goes to 11, then another tab pushes it to 16, and the final 'abc' brings the length to 19.

提交回复
热议问题