国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python中字符串內置函數的用法總結

2020-02-15 22:58:47
字體:
來源:轉載
供稿:網友

capitalize() 首字母大寫

a='someword'  b=a.capitalize()  print(b)  —>Someword

casefold()&lower() 所有字母變小寫,casefold可將未知字符便小寫

a='someWORD'   b=a.casefold()   print(b)   c=a.lower()   print(c)   —>someword   —>someword

center(width,fillchar=None) 設置寬度,并將內容居中,空白未知填充,一個字符

a='someword'   b=a.center(30,'*')   print(b)

count(sub,start=None,end=None) 去字符串中尋找,尋找子序列的出現次數,可指定起止點

a='somewordsomeword'  b=a.count(‘or')  print(b)  —>2

startswith(suffix,start=None,end=None)&endswith(suffix,start=None,end=None) 是否以XX開始/結束,可指定起止點

a='somewordsomeword'   b=a.startswith(‘sa')   c=a.endswith(‘ord')   print(b)   print(c)   —>False   —>True

find(sub,start=None,end=None) 尋找指定字符或字符串,并返回第一個位置,找不到返回-1,可指定起止點

a='somewordsomeword'   b=a.find(‘me')   print(b)   —>2

format() 格式化,將一個字符串中的占位符替換為指定的值

test='I am {name},age {a}'   v=test.format(name='alex',a=19)   print(v)   —>i am alex,age 19

format_map() 格式化,傳入的值

test='iam{name},age{a}'   v=test.format_map({“name”:'alex',”a”:19})   print(v)   —>i am alex,age 19

isalnum() 字符串中是否只包含字母和數字

a='asdfs123*'   b=a.isalnum()   print(b)   —>False

expandtabs(tabsize=number) 將字符串以number分割,并將tab補入

a='asdfs123/t523fgbdf'  b=a.expandtabs(5)  print(b) —>asdfs123 523fgbdf

isalpha() 字符串中是只包含字母

a='asdfsfgbdf'  b=a.isalpha()  print(b)  —>True

isdecimal()&isdigit()&isnumeric() 字符串中是只包含數字,isdigit更為強大,isnumeric還可識別中文

a='132132②二'   b=a.isdecimal()   c=a.isdigit()   d=a.isnumeric()   print(b)   print(c)   print(d)   —>False   —>False   —>True

isprintable() 是否存在不可顯示的字符如換行符

a='sdfgdfg/t'  b=a.isprintable()  print(b)  —>False

isspace() 判斷是否全部為空格

a='dsvsdv'   b=a.isspace()   print(b)   —>False

istitle()&title() 判斷是否為標題,即首字母大寫&變為標題

a='follow uncased characters and lowercase characters only cased ones'   b=a.istitle()   print(b)   c=a.title()   print(c)   —>False   —>Follow Uncased Characters And Lowercase Characters Only Cased Ones            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桦川县| 五河县| 大安市| 合肥市| 平江县| 策勒县| 横峰县| 娱乐| 丹巴县| 建瓯市| 东明县| 星子县| 云浮市| 万盛区| 松江区| 金秀| 海门市| 武乡县| 江阴市| 台北市| 五莲县| 洪洞县| 通山县| 曲松县| 原阳县| 淄博市| 建阳市| 红桥区| 买车| 丽水市| 武宣县| 大足县| 南华县| 克拉玛依市| 高邮市| 宁晋县| 定远县| 石楼县| 临江市| 旌德县| 莲花县|