這篇文章將為大家詳細講解有關python3 re中有什么返回形式,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
findall(pattern, string, flags=0)
在字符串string中匹配所有符合正則表達式pattern的對象,并把這些對象通過列表list的形式返回。
import re pattern = re.compile(r'\W+') result1 = pattern.findall('hello world!') result2 = pattern.findall('hello world!', 0, 7) print(result1) #[' ', '!'] print(result2) #[' ']
finditer(pattern, string, flags=0)
在字符串string中匹配所有符合正則表達式pattern的對象,并把這些對象通過迭代器的形式返回。
import re pattern = re.compile(r'\W+') result = pattern.finditer('hello world!') for r in result: print(r) # <re.Match object; span=(5, 6), match=' '> # <re.Match object; span=(11, 12), match='!'>
關于python3 re中有什么返回形式就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
當前文章:python3re中有什么返回形式-創新互聯
鏈接分享:http://vcdvsql.cn/article8/jejop.html
成都網站建設公司_創新互聯,為您提供企業建站、虛擬主機、域名注冊、手機網站建設、微信公眾號、外貿建站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯