Somewordcasefold()&lower()所有字母變小寫,casefold可將未知字符便小寫a='someWORD'b=a.casefold()print(b)c=a.lower()print(c)―>someword―>somewordcenter(width,fillchar=None)設置寬度,并將內容居中,空白未知填充,一個字符a" />

黄色网页视频 I 影音先锋日日狠狠久久 I 秋霞午夜毛片 I 秋霞一二三区 I 国产成人片无码视频 I 国产 精品 自在自线 I av免费观看网站 I 日本精品久久久久中文字幕5 I 91看视频 I 看全色黄大色黄女片18 I 精品不卡一区 I 亚洲最新精品 I 欧美 激情 在线 I 人妻少妇精品久久 I 国产99视频精品免费专区 I 欧美影院 I 欧美精品在欧美一区二区少妇 I av大片网站 I 国产精品黄色片 I 888久久 I 狠狠干最新 I 看看黄色一级片 I 黄色精品久久 I 三级av在线 I 69色综合 I 国产日韩欧美91 I 亚洲精品偷拍 I 激情小说亚洲图片 I 久久国产视频精品 I 国产综合精品一区二区三区 I 色婷婷国产 I 最新成人av在线 I 国产私拍精品 I 日韩成人影音 I 日日夜夜天天综合

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

系統 2104 0

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
          

join(iterable) 將字符串中的每個元素按照指定分隔符進行拼接

            
a='一二三四五六七' 
  print(a) 
  b='*' 
  c=b.join(a) 
  print(c) 
  ―>一二三四五六七 
  ―>一二三四五六七
          

ljust(width,fillchar=None)&rjust(width,fillchar=None) 向右/左填充字符

            
a='hello' 
 b=a.ljust(20,'*') 
 c=a.rjust(20,'*') 
 print(b) 
 print(c) 
 ―>hello*************** 
 ―>***************hello
          

islower()&lower() 判斷是是否為全小寫&變為全部小寫

            
a='Hello' 
  b=a.islower() 
  c=a.lower() 
  print(b,c) 
  ―>False hello
          

isupper()&c=a.upper() 判斷是是否為全大寫&變為全部大寫

            
a='Hello' 
  b=a.isupper() 
  c=a.upper() 
  print(b,c) 
  ―>False HELLO
          

lstrip(chars=None)&rstrip(chars=None)&strip(chars=None) 去除字符串左邊/右邊/兩邊的字符串,默認空格,換行等

            
a='Hello' 
  b=a.lstrip() 
  c=a.rstrip() 
  d=a.strip() 
  print(b) 
  print(c) 
  print(d) 
  ―>Hello 
  ―> Hello 
  ―>Hello
          

maketrans(*args,**kwargs)&translate(table) 按maketrans對應關系將translate中的字符串進行替換

            
a='asdgfrfbcvzxrentas' 
  b=str.maketrans(‘xdsa','1234') 
  c=a.translate(b) 
  print(c) 
  ―> 432gfrfbcvz1rent43
          

partition(sep)&rpartition(sep) 將字符串按指定字符分割成3段/或從右開始

            
a='helwloasvxcwaewc' 
  b=a.partition(‘w') 
  c=a.rpartition(‘w') 
  print(b) 
  print(c) 
  ―>(‘hel', ‘w', ‘loasvxcwaewc') 
  ―>(‘helwloasvxcwae', ‘w', ‘c')
          

split(sep=None,maxsplit=-1)&rsplit(sep=None,maxsplit=-1) 將字符串按指定字符串分割,分割后不保留

            
a='helwloasvxcwaewc' 
  b=a.split(‘w',2) 
  c=a.rsplit(‘w') 
  print(b) 
  print(c) 
  ―>[‘hel', ‘loasvxc', ‘aewc'] 
  ―>[‘hel', ‘loasvxc', ‘ae', ‘c']
          

splitlines(keepends=None) 按照換行符進行分割,帶true參數保留換行符

            
a='helwloas\nvxcwaewc\nafgasdfs' 
  b=a.splitlines() 
  c=a.splitlines(True) 
  print(b) 
  print(c) 
  ―>[‘helwloas', ‘vxcwaewc', ‘afgasdfs'] 
  ―>[‘helwloas\n', ‘vxcwaewc\n', ‘afgasdfs']
          

startswith(prefix,start=None,end=None)&endswith(prefix,start=None,end=None) 判斷字符串是否以指定字符開始/結束,可指定起止點

            
a='aefsfsfeeav' 
  b=a.startswith(‘ae') 
  c=a.endswith(‘av',1,9) 
  print(b) 
  print(c) 
  True 
  ―>False
          

swapcase() 小寫轉變為大寫

            
a='aefsfsfeeav' 
  b=a.swapcase() 
  print(b) 
  ―>AEFSFSFEEAV
          


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論