Python3 中的 expandtabs(tabsize = 8)

首页 / Python3入门教程 / Python3 中的 expandtabs(tabsize = 8)

Python expandstabs()方法用分隔的空格替换所有字符。默认情况下,单个选项卡会扩展为8个空格,可以根据需要覆盖这些空格。

无涯教程可以将1、2、4等传递给该方法,该方法将使用这些空格字符替换tab。

expandtabs - 语法

expandtabs(tabsize=8)

expandtabs - 参数

tabsize :它是可选的,默认值为8。

expandtabs - 返回类型

它返回修改后的字符串。

链接: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.

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Service Mesh实践指南 -〔周晶〕

消息队列高手课 -〔李玥〕

基于人因的用户体验设计课 -〔刘石〕

Spark性能调优实战 -〔吴磊〕

React Hooks 核心原理与实战 -〔王沛〕

手把手带你写一个Web框架 -〔叶剑峰〕

自动化测试高手课 -〔柳胜〕

说透元宇宙 -〔方军〕

PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕

好记忆不如烂笔头。留下您的足迹吧 :)