【Python】-- 字串

來源:互聯網
上載者:User

標籤:less   python   dex   exp   rip   列表   join   log   個數   

 

#字串操作    #定義字串    a = "let‘s go"        #字串切片    print("helloworld"[2:]) #通過索引擷取字串中的字元,和列表切片同理        #關鍵字  in     print("llo" in "helloworld")  #返回TRUE或False        #字串拼接    #可以用+拼接字串    #join實現拼接        a = "123"        b = "456"        d = "789"        c=‘***‘.join([a,b,d]) #用*拼接a,b,c        #返回123***456***789        #%  格式化輸出字串        print(‘there are some examples‘)        print(‘%s are some examples‘ %‘there‘)        #字串的內建方法    st = "hello kitty{name}"    st.count("t") #統計t的個數    st.capitalize #首字母大寫    st.center(50."#") #置中    st.endswith(‘ty‘) #以某個內容結尾    st.startswith(‘he‘) #以某個內容開頭    st.expandtabs(tabsize = 20) #修改縮排    st.find(‘t‘) #尋找,返回索引值    st.format(name = "haha") #格式化輸出的另一種方式    print(st.index(‘t‘))   #返回t的索引值    print(‘My tLtle‘.lower()) #將字串裡的字母全部轉換為小寫    print(‘My tLtle‘.upper()) #將字串裡的字母全部轉換為大寫    print(‘\tMy tLtle\n‘.strip()) #將字串裡不顯示的內容去掉    print(‘My title title‘.replace(‘itle‘,‘lesson‘,1)) #替換,replace(‘被替換的值‘,‘替換後的內容‘,1(替換幾個))    print(‘My title title‘.split(‘i‘,1)) #分割,split(‘分割值‘,分割次數)
 

【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.