python基礎3--字串,python3--字串

來源:互聯網
上載者:User

python基礎3--字串,python3--字串

字串

 

1.大小寫轉換

 1 >>> name 2 'bigberg' 3 >>> name.capitalize()   # 首字母大寫 4 'Bigberg' 5 >>> name 6 'BiGbeRg' 7 >>> name.casefold()     # 大寫字元全部改為小寫 8 'bigberg' 9 10 >>> name.upper()        # 字元全部大寫11 'BIGBERG'12 >>> name.lower()        # 字元全部小寫13 'bigberg'

2.

 1 'bigberg' 2 >>> name.center(20,'-')  # 置中,20個字元長度 3 '------bigberg-------' 4  5 >>> name.find('B')     # 尋找字元,如果存在就返回第一個的索引,不存在則返回 -1 6 -1 7 >>> name.find('b') 8 0 9 >>> name.find('g')10 211 12 >>> name.endswith('sd')   # 查詢結尾的字元13 False14 >>> name.endswith('g')15 True

3.判斷字串類型

 1 >>> name.isalpha()   # 是否為字串 2 True  3 >>> name 4 'BiGbeRg' 5 >>> a.isalpha() 6 False 7 >>> a 8 '12345' 9 >>> a.isdigit()      #是否為整數10 True11 >>> a.isnumeric()    # 是否全部為數字12 True13 14 isspace   # 是否為空白格15 is.upper() #是否全為大寫16 is.lower() #是否全為小寫17 18 >>> name             # 大小寫全部轉換19 'Bigberg'20 >>> name.swapcase()21 'bIGBERG'

4.join()

1 >>> "-".join(['123','456','789'])2 '123-456-789'

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.