dimanche 21 avril 2019

Python if output of a function

I am using the following code to find repeated characters in a string

import re
S=input()

m = re.search(r'([A-Za-z0-9])\1+',S.strip())

if m:
    print(m.group(1))
else:
    print(-1)

I am not sure why "if m:" works for me and what does it do? Does it check if m exists? (which I believe it should exist anyway), does it check if the value of m is bigger than zero?

P.S: If my input string (S) has no repeated value, then print(m) gives me an error.

Aucun commentaire:

Enregistrer un commentaire