Python Expand Tabs Length Calculation

前端 未结 2 1056
别跟我提以往
别跟我提以往 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:39

    The tab increments the column pointer to the next multiple of 8:

    >>> 'abc\tabc'.expandtabs().replace(' ', '*')
    'abc*****abc'
    

提交回复
热议问题