Project Management Answers

When capturing regex groups, what datatype does the groups method return?

Q: When capturing regex groups, what datatype does the groups method return?

or

Q: What datatype does the groups function return after collecting regex groups?

  • A string
  • A tuple
  • A list
  • A float

Explanation: When used inside the context of regex, the group’s method will return a tuple. The group’s function gives you the ability to extract the captured substrings as a tuple when you employ capturing groups in a regular expression.

If you have a regular expression pattern that has two capturing groups, for instance, invoking the group’s method will result in the return of a tuple that contains the substrings that are matched by each of the capturing groups.

Leave a Reply

Your email address will not be published. Required fields are marked *