+ 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>
8 odpowiedzi
+ 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))
+ 4
hello = re.findall(pattern, "grey")
print(hello)
+ 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)
+ 2
Hatsy Rei but if if i did anyway, what does the output means
+ 2
i tried indexing and it worked. thanks
+ 2
Anna this one works too.
means i'll have to use braces
+ 2
it returns the first letter matched.
what if i need a list of all letters matched
+ 2
thanks, i now should not forget earlier lessons