Computer >> Computer tutorials >  >> Programming >> Python

How to check if a string contains only lower case letters in Python?


We can check if a string contains only lower case letters using 2 methods. First is using method islower().

For example:

print('Hello world'.islower())
print('hello world'.islower())

OUTPUT

False
True

You can also use regexes for the same result. For matching only lowercase, we can call the re.match(regex, string) using the regex: "^[a-z]+$". For example,

print(bool(re.match('^[a-z]+$', '123abc')))
print(bool(re.match('^[a-z]+$', 'abc')))

OUTPUT

False
True