Python基礎(chǔ)入門(mén)教程17:字符串詳解及序列類(lèi)型
來(lái)源:
奇酷教育 發(fā)表于:
字符串是我們?cè)诔绦蛑惺褂梅浅6嗟囊粋€(gè)對(duì)象,對(duì)于字符串的處理在各種編程語(yǔ)言中也是非常重要的一部分。1 python中的字符串定義python中的
字符串是我們?cè)诔绦蛑惺褂梅浅6嗟囊粋€(gè)對(duì)象,對(duì)于字符串的處理在各種編程語(yǔ)言中也是非常重要的一部分。
1. python中的字符串定義
python中的字符串,可以使用單引號(hào)、雙引號(hào)或者三個(gè)單引號(hào)包含的字符,都是字符串。

2. 字符串作為模塊、類(lèi)、函數(shù)的文檔注釋
字符串你可以放在模板,類(lèi)或者函數(shù)的第一行,作為對(duì)函數(shù)的描述作用出現(xiàn),可以通過(guò)木塊、類(lèi)、函數(shù)的doc屬性進(jìn)行調(diào)用查看。

2. 字符串作為序列支持的操作方法
s[i] : 返回序列中下標(biāo)為i的元素
s[i:j]:返回序列中下標(biāo)從i到j(luò)之間的數(shù)據(jù),這樣截取數(shù)據(jù)也成為切片
s[i:j:stride]:返回一個(gè)擴(kuò)展的切片
len(s):返回序列中元素?cái)?shù)據(jù)的數(shù)量
min(s):返回序列中的最小值
max(s):返回序列中的最大值
sum(s [, initial]):返回序列中所有數(shù)據(jù)的和
all(s):檢查序列中所有的數(shù)據(jù)是否為T(mén)rue
any(s):檢查序列中任意項(xiàng)是否為T(mén)rue
capitalize() 字符串首字符大寫(xiě)
isupper() 字符串是否全部大寫(xiě)
upper() 字符串所有字符大寫(xiě)
islower() 字符串是否所有字符小寫(xiě)
lower() 字符串中所有字符小寫(xiě)
index(str [,start, end]) 獲取指定字符在字符串中出現(xiàn)的位置
t.join(s):使用字符串t來(lái)拆分字符串s,或者將一個(gè)列表s中的字符串元素按照使用t連接
replace(old, new):將指定字符串中的old字符,使用新字符new進(jìn)行替換
split(sep, max):將字符串使用指定的字符sep進(jìn)行拆分,max是拆分次數(shù),返回一個(gè)列表

、

3. 其他序列對(duì)象中常見(jiàn)的函數(shù)操作
python中除了字符串,其他的常見(jiàn)序列對(duì)象就是列表、元組、集合、字典
列表的操作
列表的操作

元組的操作

集合的操作

字典的操作
>>>更多VR/AR入門(mén)教程:VR入門(mén)