+ 2

How do I understand this kind of output?

import re pattern = r"[aeiou]" hello = re.search(pattern, "grey") print(hello.group) >>> <built-in method group of re.Match object at 0x02F2C6B0>

2nd May 2019, 7:56 AM
Bharat Upadhyay
Bharat Upadhyay - avatar
8 ответов
+ 8
group() is a method of the.Match, so you should be calling it as a method and not printing the function itself. print(hello.group(0))
2nd May 2019, 8:01 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
hello = re.findall(pattern, "grey") print(hello)
2nd May 2019, 9:56 AM
Anna
Anna - avatar
+ 3
In addition: You should never use group() alone because it will raise an exception if the pattern doesn't match the string if hello: # there is a match print(hello.group(0)) else: pass # no match => no group(0)
2nd May 2019, 8:48 AM
Anna
Anna - avatar
+ 2
Hatsy Rei but if if i did anyway, what does the output means
2nd May 2019, 9:42 AM
Bharat Upadhyay
Bharat Upadhyay - avatar
+ 2
i tried indexing and it worked. thanks
2nd May 2019, 9:45 AM
Bharat Upadhyay
Bharat Upadhyay - avatar
+ 2
Anna this one works too. means i'll have to use braces
2nd May 2019, 9:48 AM
Bharat Upadhyay
Bharat Upadhyay - avatar
+ 2
it returns the first letter matched. what if i need a list of all letters matched
2nd May 2019, 9:54 AM
Bharat Upadhyay
Bharat Upadhyay - avatar
+ 2
thanks, i now should not forget earlier lessons
2nd May 2019, 10:01 AM
Bharat Upadhyay
Bharat Upadhyay - avatar