Python expandtabs()方法

2025-12-01 0 7,273

描述

Python expandtabs() 方法把字符串中的 tab 符号(‘t’)转为空格,默认的空格数 tabsize 是 8。

语法

expandtabs()方法语法:

string.expandtabs(tabsize=8)

参数

tabsize — 指定转换字符串中的 tab 符号(‘t’)转为空格的字符数。

返回值

该方法返回字符串中的 tab 符号(‘t’)转为空格后生成的新字符串。

实例

以下实例展示了expandtabs()方法的实例:

#!/usr/bin/python
 
string = "this iststring example....wow!!!";
 
print "Original string: " + string
print "Defualt exapanded tab: " +  string.expandtabs()
print "Double exapanded tab: " +  string.expandtabs(16)

以上实例输出结果如下

Original string: this is        string example....wow!!!
Defualt exapanded tab: this is string example....wow!!!
Double exapanded tab: this is         string example....wow!!!

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:以上部本文内容由互联网用户自发贡献,本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。投诉邮箱:3758217903@qq.com

ZhiUp资源网 python基础 Python expandtabs()方法 https://www.zhiup.top/5792.html

相关