




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、 s=apple,peach,banana,pear li=s.split(,) liapple, peach, banana, pear s.partition(,)(apple, , peach,banana,pear) s.rpartition(,)(apple,peach,banana, , pear) s.rpartition(banana)(apple,peach, banana, ,pear)s = 2014-10-31 t=s.split(-) print t2014, 10, 31 print map(int, t)2014, 10, 31對于split()和rsplit()
2、方法,如果不指定分隔符,則字符串中的任何空白符號(包括空格、換行符、制表符等等)都將被認為是分隔符,返回包含最終分割結果的列表。 s = hello world nn My name is Dong s.split()hello, world, My, name, is, Dong s = nnhello world nnn My name is Dong s.split()hello, world, My, name, is, Dong s = nnhellott world nnn My namet is Dong s.split()hello, world, My, name, is,
3、Dongsplit()和rsplit()方法還允許指定最大分割次數,例如: s = nnhellott world nnn My name is Dong s.split(None,1)hello, world nnn My name is Dong s.rsplit(None,1)nnhellott world nnn My name is, Dong s.split(None,2)hello, world, My name is Dong s.rsplit(None,2)nnhellott world nnn My name, is, Dong s.split(None,5)hello,
4、world, My, name, is, Dong s.split(None,6)hello, world, My, name, is, Dongnlower()、upper()、capitalize()、title()、swapcase()這幾個方法分別用來將字符串轉換為小寫、大寫字符串、將字符串首字母變為大寫、將每個單詞的首字母變為大寫以及大小寫互換。 s=What is Your Name? s2=s.lower() s2what is your name? s.upper()WHAT IS YOUR NAME? s2.capitalize()What is your, name? s.
5、title()What Is Your Name? s.swapcase()wHAT IS yOUR nAME?n內置函數eval() eval(3+4)7 a = 3 b = 5 eval(a+b)8 import math eval(help(math.sqrt)Help on built-in function sqrt in module math:sqrt(.) sqrt(x) Return the square root of x. eval(math.sqrt(3)1.7320508075688772 eval(aa)Traceback (most recent call las
6、t): File , line 1, in eval(aa) File , line 1, in NameError: name aa is not defined返回指定寬度的新字符串,原字符串居中、左對齊或右對齊出現在新字符串中,如果指定寬度大于字符串長度,則使用指定的字符(默認為空格)進行填充。 Hello world!.center(20) Hello world! Hello world!.center(20,=)=Hello world!= Hello world!.ljust(20,=)Hello world!= Hello world!.rjust(20,=)=Hello wo
7、rld!則表達式是普通字符串,可以匹配自身npjcython可以匹配python、jython、cythonna-zA-Z0-9可以匹配一個任意大小寫字母或數字nabc可以一個匹配任意除a、b、c之外的字符npython|perl或p(ython|erl)都可以匹配python或perln子模式后面加上問號表示可選。r(http:/)?(www.)?只能匹配、、和nhttp只能匹配所有以http開頭的字符串n(pattern)*:允許模式重復0次或多次n(
8、pattern)+:允許模式重復1次或多次n(pattern)m,n import re text = alpha. beta.gamma delta re.split(. +,text)alpha, beta, gamma, delta re.split(. +,text,maxsplit=2)#分割2次alpha, beta, gamma delta re.split(. +,text,maxsplit=1)#分割1次alpha, beta.gamma delta pat = a-zA-Z+ re.findall(pat,text) #查找所有單詞alpha, beta, gamma, d
9、elta pat = name text = Dear name. re.sub(pat,Mr.Dong,text) #字符串替換Dear Mr.Dong. s = a s d re.sub(a|s|d,good,s) #字符串替換good good good re.escape() #字符串轉義n刪除字符串中重復的空格 import re s=aaa bb c d e fff re.split(s+,s)aaa, bb, c, d, e, fff, re.split(s+,s.strip()aaa, bb, c, d, e, fff .join(re.split(s+,s.strip()aaa bb c d e fff .join(re.split(s
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 勵志演講稿1000字(18篇)
- 食堂經營承包方案策劃書
- 籃球比賽活動實施方案(5篇)
- 高校輔導員培訓課件
- 初中物理期末教學總結(4篇)
- 勞務合同格式2025(18篇)
- 上海市氣功研究所工作人員招聘筆試真題2024
- 2024年龍巖市新羅區國有資產經營集團有限公司招聘考試真題
- 紡織行業中的產品包裝與物流管理考核試卷
- 2024年江西中醫藥大學附屬醫院編制外招聘工作人員考試真題
- 臺達DELTA變頻器VFD-EL系列使用說明書和手冊(完整中文版)VFD007EL23A
- 2025年山西汾西礦業集團公司招聘筆試參考題庫含答案解析
- 2024年度英語課件容貌焦慮
- 神經外科質量與安全管理工作計劃
- 城市違建拆除施工方案
- 復色激光光譜分析研究
- 農藥代銷協議書模板
- 《電力中長期交易合同示范文本(2022年修訂版)》
- 小學班會 世界知識產權日知識產權宣傳周主題班會 課件
- 3.2平均數的計算(1)(教學課件)五年級數學上冊 滬教版
- 2024年版《輸變電工程標準工藝應用圖冊》
評論
0/150
提交評論