python學習筆記---字符串操做

字符串屬於python序列中的一種,屬於不可變序列,不支持插入、刪除和替換操做。
python

1,如何定義一個字符串:ide

image.png

2,字符串運算---索引運算s[i]: 返回字符串中索引爲i的元素函數

image.png

3,字符串運算---切片運算s[i:j:k]: 返回一個新的字符串,內容爲以i索引開頭到j索引介紹,步長爲k的字符串3d

image.png

4,字符串運算---內置函數:對象

      len(s) : s中的元素個數blog

      min(s):s中最小值索引

      max(s):s中最大值   (最大、最小值按照字符的ascii碼決定)
ip

image.png

五、字符串對象經常使用方法:ci

    s.captitalize()  將s首字符大寫
字符串

image.png

    s.index(sub [,start,[,end]]) 找到子字符串首次出現的位置,若是沒找到就報錯

image.png

    s.join(s1) 使用s做爲分隔符鏈接字符串s1中的每一個字符

image.png

    s.lower(),s.upper()   將字符串轉換成小寫、大寫

image.png

    s.replace(old,new [,maxreplace])  將old串替換成new串

image.png

image.png

    s.splite([sep [.maxsplit]])  使用sep做爲分隔符對s進行劃分,maxsplit是劃分的最大次數

image.png

    s.strip([ch]) 刪掉ch開頭和結尾的字符,默認是刪除空白字符

image.png

相關文章
相關標籤/搜索