它返回跳位字元字元,即字串的副本。 “\t”使用空格,可以選擇使用給定的tabsize(默認8)擴展。
語法
str.expandtabs(tabsize=8)
參數
-
tabsize -- 指定要替換為跳位字元 '\t' 的字元數
-
返回值
-
此方法返回字串的一個副本,跳位字元字元,即 '\t' 已經使用空格擴展。
示例
#!/usr/bin/python3
str = "this is\tstring example....wow!!!"
print ("Original string: " + str)
print ("Defualt exapanded tab: " + str.expandtabs())
print ("Double exapanded tab: " + str.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!!!
