Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the differences between match () and search () in Python

Shulou Source: shulou.com Published: 2022-06-01 03:48:57 10月02日 Update

This article mainly introduces the difference between match() and search() in Python, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.

What is the difference between match() and search() in Python?

A: match(pattern,string[,flags]) in the re module, check whether the beginning of string matches pattern.

In the re module re.search (pattern,string[,flags]), search string for the first match of pattern.

>>>print (re.match('super', 'superstition').span()) (0, 5)>>>print (re.match('super', 'insuperable')) None>>>print (re.search('super', 'superstition').span()) (0, 5)>>>print (re.search ('super ',' superable').span()) (2, 7) Thank you for reading this article carefully. I hope that Xiaobian shares "What are the differences between match() and search() in Python" This article is helpful to everyone. At the same time, I hope everyone will support it a lot. Pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!

Tags: Articles modules value interests at the same time beginning more friends knowledge editing industry information information channels channels references learning help search support check Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Linux Huawei macOS Microsoft