Python expandstabs()方法用分隔的空格替换所有字符。默认情况下,单个选项卡会扩展为8个空格,可以根据需要覆盖这些空格。
无涯教程可以将1、2、4等传递给该方法,该方法将使用这些空格字符替换tab。
tabsize :它是可选的,默认值为8。
它返回修改后的字符串。
链接:https://www.learnfk.comhttps://www.learnfk.com/python3/python-string-expandtabs-method.html
来源:LearnFk无涯教程网
不指定空格的调用方法。设置为默认值。
# Python endswith() function example # 变量声明 str = "Welcome \t to \t the \t Learnfk." # 函数调用 str2 = str.expandtabs() # 显示结果 print(str2)
输出:
Welcome to the Learnfk.
每种方法都设置为不同数量的空格。
# Python endswith() function example # 变量声明 str = "Welcome \t to \t the \t Learnfk." # 函数调用 str2 = str.expandtabs(1) str3 = str.expandtabs(2) str4 = str.expandtabs(4) # 显示结果 print(str2) print(str3) print(str4)
输出:
Welcome to the Learnfk. Welcome to the Learnfk. Welcome to the Learnfk.
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)