Python 3 – String islower() Method
In Python programming language, a string is a sequence of characters. It is one of the most commonly used data types in python. The islower() method is a built-in method in the Python string that returns “True” if all the characters in the string are in lowercase, otherwise it returns “False”.
Syntax
The syntax of the islower() method is as follows:
string.islower()
Parameters
The islower() method does not take any parameters.
Return Value
- True: If all the characters in the given string are in lowercase.
- False: If any of the characters in the given string are not in lowercase or there are no characters in the given string.
Example
Here is an example that demonstrates the usage of the islower() method:
# Example 1
string1 = "abcdefghijklmnopqrstuvwxyz"
print(string1.islower()) # Output: True
# Example 2
string2 = "Hello World"
print(string2.islower()) # Output: False
# Example 3
string3 = "hello world 123"
print(string3.islower()) # Output: True
# Example 4
string4 = "PYTHON IS COOL"
print(string4.islower()) # Output: False
Explanation
- In Example 1, all the characters in the given string “abcdefghijklmnopqrstuvwxyz” are in lowercase, so the output is “True”.
-
In Example 2, the given string “Hello World” contains uppercase characters, so the output is “False”.
-
In Example 3, the given string “hello world 123” only contains lowercase characters and numbers, so the output is “True”.
-
In Example 4, the given string “PYTHON IS COOL” contains uppercase characters, so the output is “False”.
Conclusion
The islower() method is a very useful string method in Python. It can be used to determine if all the characters in an input string are in lowercase or not. This method is very helpful in tasks such as data validation and string manipulation. It is important to keep in mind that the islower() method only works with the English alphabet and not with non-English characters.