新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Python expandtabs()
python 中的expandtabs()函數(shù)有助于將字符串中的' \t '字符替換為空格。該函數(shù)允許指定所需的空間量。最后,修改后的字符串作為輸出返回。

濰城ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
**string.expandtabs(tabsize)** #where tabsize is an integer valueexpandtabs()參數(shù):
expandtabs()函數(shù)接受一個(gè)參數(shù)。如果我們需要替換多個(gè)制表符,那么制表符之前的字符只有在到達(dá)前一個(gè)制表符時(shí)才被計(jì)數(shù)。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| tabsize | 指定 tabsize 的數(shù)字。默認(rèn) tabsize 為 8 | 可選擇的 |
expandtabs()返回值
返回值始終是字符串。它返回使用空格擴(kuò)展后的原始字符串的副本。
| 投入 | 返回值 | | 線 | 帶有空格的字符串 |
Python 中expandtabs()方法的示例
示例 1:如何在沒有參數(shù)的情況下使用expandtabs()?
string = 'abc\t56789\tefg'
# no argument is passed
# default tabsize is 8
result = string.expandtabs()
print(result)
輸出:
abc 56789 efg示例 2:如何用不同的參數(shù)擴(kuò)展?
string = "abc\t56789\tdef"
print('Original String:', str)
# tabsize is set to 2
print('Expanded tabsize 2:', string.expandtabs(2))
# tabsize is set to 3
print('Expanded tabsize 3:', string.expandtabs(3))
# tabsize is set to 4
print('Expanded tabsize 4:', string.expandtabs(4))
# tabsize is set to 5
print('Expanded tabsize 5:', string.expandtabs(5))
# tabsize is set to 6
print('Expanded tabsize 6:', string.expandtabs(6))
輸出:
Original String: abc 56789 def
Expanded tabsize 2: abc 56789 def
Expanded tabsize 3: abc 56789 def
Expanded tabsize 4: abc 56789 def
Expanded tabsize 5: abc 56789 def
Expanded tabsize 6: abc 56789 def 標(biāo)題名稱:創(chuàng)新互聯(lián)Python教程:Python expandtabs()
網(wǎng)站地址:http://www.dlmjj.cn/article/cdjcoog.html


咨詢
建站咨詢
