+ 8

This code confuses me. How does it work although it's drastically changed?

https://code.sololearn.com/cHQ0R9r46K1i/?ref=app

22nd Mar 2018, 10:31 PM
Vučko/Вучко/Vuchko
Vučko/Вучко/Vuchko - avatar
2 Réponses
+ 4
The way that re.match works is that it searches for a specific pattern within the string, in this case being spam, and returning true if it finds it anywhere within as a substring. This means that it doesn't have to be the entire string, but just apart of it.
22nd Mar 2018, 10:35 PM
Faisal
Faisal - avatar
+ 3
Code: pattern = r'spam' target = "spamsyxzytrdguytrzwxxx" re.match(pattern, target) Translation: try to find in the beginning of target an 's' folowed by a 'p' then an 'a' and then a 'm'.
22nd Mar 2018, 11:49 PM
Ulisses Cruz
Ulisses Cruz - avatar