python中expandtabs 函式的用法

2022-09-17 02:09:13 字數 1671 閱讀 3246

練習題:製作**

迴圈提示使用者輸入:使用者名稱、密碼、郵箱(要求使用者輸入的長度不能超過20個字元,如果超過則只有前20個字元有效),如果使用者輸入q或者q表示不再繼續輸入,將使用者的內容一**形式列印

s = ""

while true:

v1 = input('請輸入你的名字')

v2 = input('請輸入你的密碼')

v3 = input('請輸入你的郵箱')

v4 = v1[0:19]

v5 = v2[0:19]

v6 = v3[0:19]

test = "\t\t\n"

v = test.format(v4, v5, v6)

b = v.expandtabs(20)

s = s + b

if v1 == "q" or v2 == "q" or v3 == "q" or v1 == "q" or v2 == "q" or v3 == "q":

break

print(s)

​請輸入你的名字q

​請輸入你的密碼ww

​請輸入你的郵箱ee

​aa bb cc

​dd dd dd

​ff ff ff

​q ww ee

expandtabs()函式

描述:返回乙個字串的副本。使原字串中的製表符("\t")的使用空間變大。使用空格來擴充套件空間。

語法: str.expandtabs(tabsize=8)  —> str  返回字串

tabsize 的預設值為8。tabsize值為0到7等效於tabsize=8。tabsize每增加1,原字串中「\t」的空間會多加乙個空格。

示例:

str = "this is\tstring example....wow!!!"

print(str.expandtabs())#預設值為8

print(str.expandtabs(tabsize=8))

print(str.expandtabs())

print(str.expandtabs(2)) #tabsize值為0到7,與tabsize值為8相同

print(str.expandtabs(tabsize=2))

print(str.expandtabs(tabsize=9))

print(str.expandtabs(tabsize=10))

執行結果:

this is string example....wow!!!

this is string example....wow!!!

this is string example....wow!!!

this is string example....wow!!!

this is string example....wow!!!

this is string example....wow!!!

this is string example....wow!!!

python中 python中的 與

這一部分首先要理解python記憶體機制,python中萬物皆物件。對於不可變物件,改變了原來的值,其別名 變數名 繫結到了新值上面,id肯定會改變 對於可變物件,操作改變了值,id肯定會變,而 是本地操作,其值原地修改 對於 號操作,可變物件和不可變物件呼叫的都是 add 操作 對於 號操作,可變...

python中否定for 在python中否定函式

有沒有一種方法可以否定乙個函式,使它返回負數。在我的函式中,我有條件句,每個條件句都讓這個 烏龜 移動。有沒有一種方法可以否定這一點,所以烏龜的每乙個動作都是否定的。我說的是 狀況 在def ttinterpret program interpret program as a tinyturtle ...

python中雙重迴圈 加速Python中的雙迴圈

有沒有辦法加快從上一次迭代更新其值的雙迴圈?在 中 def calc n,m x 1.0 y 2.0 container np.zeros n,2 for i in range n for j in range m x np.random.gamma 3,1.0 y y 4 y np.random....