字串基礎1

來源:互聯網
上載者:User

標籤:case   font   for   包含   ***   一個   print   end   指定   

# capitalize  輸出首字母大寫
# test=‘leI‘
# v=test.capitalize()
# print(v)

# casefold 輸出全小寫(特殊語言也可以,用的少)
# lower 輸出全小寫

# center 置中 可加填充 填充只能單字元(填充可有可無)
# test=‘lei‘
# v=test.center(20,‘*‘)
# print(v)
#********lei*********

# count 統計出現字元次數 後面可加範圍
# test=‘leileileilei‘
# v=test.count(‘l‘,5,8)
# print(v)
# 1

# endswith startswith 判斷開頭和結尾 後面可加範圍
# test=‘leio‘
# v1=test.endswith(‘io‘)
# v2=test.startswith(‘le‘)
# print(v1,v2)
# True True

# find 從開始往後找 找到第一個後輸出位置,後面可加範圍 -1 沒找到
# test = ‘leilei‘
# v = test.find(‘il‘)
# print(v)
# 2

#index 找不到報錯,用find不報錯 列表中可用於索引位置尋找序列

# format 格式化,將一個字串佔位替換為指定值
# test = ‘i am {name}‘
# print(test)
# v = test.format(name=‘lei‘)
# print(v)
#i am {name}
# i am lei

# test = ‘i am {name},age{a}‘
# v1 = test.format(name=‘lei‘,a=10)
# v2 = test.format_map({‘name‘:‘lei‘,‘a‘:22})
# print(v1,v2)
# i am lei,age10 i am lei,age22

# isalnum 判斷字串中包含數字和字母,有其他特殊字元則False
# test = ‘asds12324‘
# v = test.isalnum()
# print(v)
#Ture

字串基礎1

聯繫我們

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