How to use the split method of Python
This article mainly introduces the Python split method of how to use the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that we read this Python split method how to use the article will have a harvest, let's take a look.
Re.split
The split method splits the string into substrings that can match and returns the list. It is used in the following form:
Re.split (pattern, string [, maxsplit=0, flags=0])
Parameters:
Parameter describes the string to be matched by the regular expression string that pattern matches. The number of maxsplit segmentation, maxsplit=1 segmentation once, default is 0, unlimited number of times. Flags flag bit, which is used to control how regular expressions are matched, such as case sensitivity, multi-line matching, and so on. Example
> import re
> re.split ('\ runoob, 'runoob, runoob, runoob.') [' runoob',']
> re.split ('(\ W+)', 'runoob, runoob, runoob.') [', 'runoob',','']
> re.split ('\ runoob, runoob, runoob.', 1) [', 'runoob, runoob, runoob.']
> re.split ('a match, 'hello world') # split will not split a string that cannot find a match [' hello world']
This is the end of the article on "how to use the split method of Python". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use the split method of Python". If you want to learn more, you are welcome to follow the industry information channel.