Python 字串操作函數二

來源:互聯網
上載者:User

標籤:函數   ==   this   lines   enter   strip()   new   傳回值   pac   

#-*- coding:utf-8 -*-line = "l want watch movie with you ."print(line.center(50))print(line.ljust(50))print(line.rjust(50))#center 字串置中#ljust 字串居左#rjust 字元中居右#lstrip 刪除字串左邊的空白字元#rstrip 刪除字串右邊的空白字元#strip 刪除字串兩端的空白字元word = "\n \t  i am a bird . \n \r "print("==lstrip==")print(word.lstrip())print("===rstrip==")print(word.rstrip())print("==strip==")print(word.strip())#空白字元包括空格 /n /t等不可見字元nword = "hello this a new world ."print("==partition==")#partitionprint(nword.partition("a"))#在源字串中從左向右尋找指定字串,找到指定字串做切割,分為3部分,指定字串前,後,其本身,傳回值是元組#如果指定字串不存在於源字串中,那麼結果由源字串本身,兩個Null 字元串組成#rpartition 從右向左尋找指定字串wline = "hello \n world"print("==splitlines==")print(wline.splitlines())#splitlines 按照行進行分割,返回一個包含各行作為元素 的列表print("==isalpha==")print(wline.isalpha())  #返回false 因為存在空格,逸出字元#isalpha 判斷字串中所有字元是否都是字母,字母返回true,其他返回falsenum = "12233"print("==isdigit==")print(num.isdigit())#isdigit 判斷字串中所有字元是否都是數字,是返回true,其他返回falsestr="sadfa213"print("==isalnum==")print(str.isalnum())#isalnum 字串是否只由數字和字母組成,是返回true,其他返回falsespace="  "print("==isspace==")print(space.isspace())#isspace 判斷字串中是否只有空格,是返回true,其他返回falseprint("==join==")tstr = "_"list1 = ["aa","bb"]print(tstr.join(list1))#每個字元後面都插入指定的字元,構成一個新的字串

 

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.