\t:格式化制表符后首字符位置为最小整数倍制表位位置。
str = "this is\tstring example....wow!!!"
# 删除\t:设置为≤0整数
print("替换 \\t 符号: " + str.expandtabs(0))
# 当前置字符串长度为整数倍制表位长度时,替换为制表位长度(1空格)
print("替换 \\t 符号: " + str.expandtabs(1))
# \t被替换为1空格:math.ceil(len("this is")/2)*2-len("this is")
print("替换 \\t 符号: " + str.expandtabs(2))
# \t被替换为2空格:math.ceil(len("this is")/3)*3-len("this is")
print("替换 \\t 符号: " + str.expandtabs(3))
# 当前置字符串长度为整数倍制表位长度时,替换为制表位长度(7空格)
print("替换 \\t 符号: " + str.expandtabs(7))
输出:
替换 \t 符号: this isstring example....wow!!!
替换 \t 符号: this is string example....wow!!!
替换 \t 符号: this is string example....wow!!!
替换 \t 符号: this is string example....wow!!!
替换 \t 符号: this is string example....wow!!!
Rocky2188
Rocky2188
271***81@qq.com4个月前 (07-31)