接上次補充:git
s = "username\temail\tpassword\naaa\taa@qq.com\t123\nusername\temail\tpassword\naaa\taa@qq.com\t123" a = s.expandtabs(20) #斷句,以20爲單位,不夠就自動補齊20個 print(a)
運算結果:spa
username email password aaa aa@qq.com 123 username email password aaa aa@qq.com 123 Process finished with exit code 0
其餘功能:code
1.blog
#判斷當前輸入是否爲數字 test = '②' a1 = test.isdecimal() #僅支持數字 a2 = test.isdigit() #支持特殊符號和數字 a3 = test.isnumeric() #支持全部包括中文 print(a1,a2,a3)
運算結果:ip
False True True
Process finished with exit code 0
2.ci
test = 'sjalfaj\tafaaf' a1 = test.isprintable() # 是否存在不可顯示的字符 print(a1)
運算結果:字符串
False
Process finished with exit code 0
test = 'sjalfajafaaf' a1 = test.isprintable() # 是否存在不可顯示的字符 print(a1)
運算結果:it
True
Process finished with exit code 0
3.判斷字符串裏是否全是空格io
test = 'sjalfa jafaaf' a1 = test.isspace() # 是否全是空格 print(a1)
運算結果:table
False
Process finished with exit code 0
4.判斷是不是標題(首字母大寫)
test = 'sjalfa jafaaf' a1 = test.istitle() print(a1)
運算結果:
False
Process finished with exit code 0
5.變成標題
test = 'sjalfa jafaaf' a1 = test.istitle() a2 = test.title() print(a1) print(a2)
運算結果:
False
Sjalfa Jafaaf
Process finished with exit code 0
6.
#將字符串中的每個元素按照指定分隔符進行拼接 test = '你好啊豬頭' print(test) t = ' ' a = t.join(test) #或者 把t.join(test)改爲' '.join(test) print(a)
運算結果:
你好啊豬頭
你 好 啊 豬 頭
Process finished with exit code 0
7.填充
test = 'abcd' a = test.ljust(20,'*') a1 = test.center(20,'中') print(a) print(a1)
運算結果:
abcd****************
中中中中中中中中abcd中中中中中中中中
Process finished with exit code 0
8.只用00填充
test = 'abcd' a = test.zfill(20) print(a)
運算結果:
0000000000000000abcd
Process finished with exit code 0
9.
test = 'ABCD' a = test.islower() # 判斷是否爲小寫 a1 = test.lower() # 所有變成小寫 print(a,a1)
運算結果:
False abcd
Process finished with exit code 0
10.
test = 'abcd' a = test.isupper() # 判斷是否爲大寫 a1 = test.upper() #變成大寫 print(a,a1)
運算結果:
False ABCD
Process finished with exit code 0
11.去掉空白(換行\n,空格\t也能去掉)
test = ' abcd ' a = test.lstrip() # 去掉左邊空白 #a1 = test.rstrip() #去掉右邊空白 #a2 = test.strip() # 去掉所有空白 print(a)
12.移除指定字符串
test = 'abcd' a = test.lstrip("a") print(a)
運算結果:
bcd
Process finished with exit code 0
13.分割
test = 'lovesdcvvf' a = test.partition('v') #只能將整個字符串分割成3份 a1 = test.rpartition('v') #從右開始分割成3份 a2 =test.split("v",2) #所有分割 a3 = test.rsplit() #從右開始所有分割 print(a) print(a1) print(a2) print(a3)
運算結果:
('lo', 'v', 'esdcvvf') ('lovesdcv', 'v', 'f') ['lo', 'esdc', 'vf'] ['lovesdcvvf'] Process finished with exit code 0
14.
test = 'adfsdf\nsafafsad\ndsaf' a = test.splitlines(True) # 只能根據換行分割, 布爾值用來是否顯示換行符 print(a)
運算結果:
['adfsdf\n', 'safafsad\n', 'dsaf'] Process finished with exit code 0
15.
test = 'adfsdf\nsafafsad\ndsaf' a = test.startswith('a') #判斷是否以a開頭的 b = test.endswith("a") #判斷是否以a結尾 print(a) print(b)
運算結果:
True
False
Process finished with exit code 0
16.大小寫轉換
test = 'abc' a = test.swapcase() print(a)
運算結果:
ABC
Process finished with exit code 0