opper 將字串中的所有的字母轉化為大寫
lower 將字串當中的所有字母轉化為小寫
swapcase 將字串當中的所有字母大寫小寫互換
title 將字串當中的單詞首字母大寫,單詞以非字母劃分
capitalize 只有字串的首字母大寫
expandtabs 吧字串中的tab符號('/t')轉換為空格,tab 符號('/t')預設的空格數是8
s = 'hello python'
print(s.upper())
print(s.lower())
print(s.swapcase())
print(s.title())
print(s.capitalize())
s1 ='hello \t python'
print(s1.expandtabs())
'''hello python
hello python
hello python
hello python
hello python
hello python
'''
isalnum 判斷字串是否完全由字母或數字組成
isalpha 判斷字串是否完全由字母組成
isdigit 判斷字串是否完全由數字組成
isupper 判斷字串當中的字母是否完全是大寫
islower 判斷字串當中的字母是否完全是小寫
istitle 判斷字串是否滿足title格式
isspace 判斷字串是否完全有空格組成
startswith 判斷字串的開頭字元,也可以擷取判斷
endswith 判斷字串的結尾字元,也可以擷取判斷
split 判斷字串的分隔符切片
s1 = '10a-'
print(s1.isalnum())
s2 = 'hello'
print(s2.isalpha())
s3 = '234'
print(s3.isdigit())
s4 = 'hello'
print(s4.isupper())
s5 = 'hello'
print(s5.islower())
s6 = 'hello python'
print(s6.istitle())
s7 = ' '
print(s7.isspace())
s8 = 'hello python'
print(s8.startswith('he'))
print(s8.endswith('on'))
print(s8.endswith('io',0,5))
false
true
true
true
true
true
true
true
true
false
Python基礎4 字串
python字串是由數字 字母 下劃線組成的一串字元,我們可以使用引號來建立字串。如 str helloworld 在python中沒有char型別,單個字元也作為string使用 python的字串列表有2種取值順序 a.自左向右,預設索引從0開始,索引長度最長為字串長度 1 b.自右向左,預設索...
Python學習4 字串
1.python字串 python沒有字元,所有的都叫做字串,用單引號表示。2.python中字串,列表,元祖的相似性 1 訪問,都是用str i 來訪問第i 1個元素。2 切片,str i j 來擷取其中的一部分。3 拼接,若要向其中插入一部分,都要使用str i str2 str i 但是此過程...
Python基礎 七 字串
python字串 python 訪問字串中的值 python 不支援單字元型別,單字元在 python 中也是作為乙個字串使用。python 訪問子字串,可以使用方括號來擷取字串,如下例項 var1 hello world var2 runoob print var1 0 var1 0 print ...