What are the differences between match () and search () in Python
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!