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

PythonServer Side ProgrammingProgramming

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
raja
Published on 08-Dec-2017 16:03:57
Advertisements