Question:

Explain split(), sub(), subn() methods of “re” module in Python.

Answer:

To modify the strings, Python’s “re” module is providing 3 methods. They are:
split() – uses a regex pattern to “split” a given string into a list.
sub() – finds all substrings where the regex pattern matches and then replace them with a different string
subn() – it is similar to sub() and also returns the new string along with the no. of
replacements.


Keywords:

© 2017 QuizBucket.org