python之字串函數

來源:互聯網
上載者:User

標籤:and   分享圖片   class   src   字元   ali   nbsp   int   code   

1.  endswith()  startswith()

1 # 以什麼什麼結尾2 # 以什麼什麼開始3 test = "alex"4 v = test.endswith(‘ex‘)5 v = test.startswith(‘ex‘)6 print(v)
View Code

2. expandtabs()

1 test = "1\t2345678\t9"2 v = test.expandtabs(6)3 print(v,len(v))
View Code

3. find()

1 # 從開始往後找,找到第一個之後,擷取其未知2 # > 或 >=3 test = "alexalex"4 # 未找到 -15 v = test.find(‘e‘)6 print(v)
View Code

4.  index()

1 # index找不到,報錯   忽略2 test = "alexalex"3 v = test.index(‘a‘)4 print(v)
View Code

5. format()  format_map()

 1 # 格式化,將一個字串中的預留位置替換為指定的值 2 test = ‘i am {name}, age {a}‘ 3 print(test) 4 v = test.format(name=‘alex‘,a=19) 5 print(v) 6  7 test = ‘i am {0}, age {1}‘ 8 print(test) 9 v = test.format(‘alex‘,19)10 print(v)11 12 # 格式化,傳入的值 {"name": ‘alex‘, "a": 19}13 test = ‘i am {name}, age {a}‘14 v1 = test.format(name=‘df‘,a=10)15 print(v1)16 v2 = test.format_map({"name": ‘alex‘, "a": 19})17 print(v2)
View Code

6. isalnum()

1 # 字串中是否只包含 字母和數字2 test = "er;"3 v = test.isalnum()4 print(v)
View Code

 

python之字串函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.