Check if a string contains any lowercase letters | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Check if a string contains any lowercase letters

The answer I found is this however I do not understand how it works. Can someone plz explain or show another method. Thank you in advance def any_lowercase(s): flag = False for c in s: flag = flag or c.islower() return flag print(any_lowercase('HELP')) False print(any_lowercase('help')) True print(any_lowercase('HeLP')) True

25th Sep 2017, 2:11 PM
JUGHEAD
JUGHEAD - avatar
1 Resposta
+ 2
I don't get what you don't get šŸ˜‰ the key is the Boolean OR in line 4 OR returns False only when both sides are False, otherwise it returns True. that's the whole secret I'd suggest to take a piece of paper and draw a table of variables for every step of the loop. For a single use I'd do this: s print (any (c.islower() for c in s))
25th Sep 2017, 3:29 PM
Skipper
Skipper - avatar