python - How to check if lowercase letters exist? -
i have been observing unusual behavior .islower()
, .isupper()
methods in python. example:
>>> test = '8765iouy9987oiuy' >>> test.islower() false >>> test.isupper() false
however, following mixed string value seems work:
>>> test2 = 'b1' >>> test2.islower() true >>> test2.isupper() false
i not understand anomaly. how can detect lower case letters in test
?
islower()
, isupper()
return true
if all letters in string lowercase or uppercase, respectively.
you'd have test individual characters; any()
, generator expression makes relatively efficient:
>>> test = '8765iouy9987oiuy' >>> any(c.islower() c in test) true >>> any(c.isupper() c in test) true
Comments
Post a Comment