五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

python字符串常用方法

發(fā)布日期:2021-12-19 02:31 | 文章來源:gibhub

1、find(sub[, start[, end]])

在索引startend之間查找字符串sub
​找到,則返回最左端的索引值,未找到,則返回-1
startend都可省略,省略start說明從字符串開頭找
省略end說明查找到字符串結尾,全部省略則查找全部字符串

source_str = "There is a string accessing example"
print(source_str.find('r'))
>>> 3
 

2、count(sub, start, end)

返回字符串substartend之間出現(xiàn)的次數(shù)

source_str = "There is a string accessing example"
print(source_str.count('e'))
>>> 5
 

3、replace(old, new, count)

old代表需要替換的字符,new代表將要替代的字符,count代表替換的次數(shù)(省略則表示全部替換)

source_str = "There is a string accessing example"
print(source_str.replace('i', 'I', 1))
>>> There Is a string accessing example # 把小寫的i替換成了大寫的I
 

4、split(sep, maxsplit)

sep為分隔符切片,如果maxsplit有指定值,則僅分割maxsplit個字符串
分割后原來的str類型將轉換成list類型

source_str = "There is a string accessing example"
print(source_str.split(' ', 3))
>>> ['There', 'is', 'a', 'string accessing example'] # 這里指定maxsplit=3,代表只分割前3個
 

5、startswith(prefix, start, end)

判斷字符串是否是以prefix開頭,startend代表從哪個下標開始,哪個下標結束

source_str = "There is a string accessing example"
print(source_str.startswith('There', 0, 9))
>>> True
 

6、endswith(suffix, start, end)

判斷字符串是否以suffix結束,如果是返回True,否則返回False

source_str = "There is a string accessing example"
print(source_str.endswith('example'))
>>> True
 

7、lower

將所有大寫字符轉換成小寫

8、upper

將所有小寫字符轉換成大寫

9、join

將列表拼接成字符串

list1 = ['ab', 'cd', 'ef']
print(" ".join(list1))
>>> ab cd ef
 

10、切片反轉

list2 = "hello"
print(list2[::-1])
>>> olleh

到此這篇關于python字符串常用方法的文章就介紹到這了,更多相關python字符串內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持本站!

版權聲明:本站文章來源標注為YINGSOO的內(nèi)容版權均為本站所有,歡迎引用、轉載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。

相關文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務

7x24全年不間斷在線

專屬顧問服務

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務熱線

關注
微信

關注官方微信
頂部