To get to know the type of characters in a string there are several inbuilt methods in python. Here are the list of methods:
- isalpha()
- returns True if there are only alphabets in the string else it returns False
- isdigit()
- returns True if there are only numbers in the string else it returns False
- isalnum()
- returns True if there are both numbers and characters in the string else it returns False
- isupper()
- returns True if all the characters in the string are upper case letters else it returns False
- islower()
- returns True if all the characters in the string are lower case letters else it returns False
- isTitle()
- returns True if first letter in the string starts with upper case else it returns False
The output of these methods is True or False.
Example:
For the below code, output is False as there are both numbers and characters and not just characters.
string = "Way2Know"
string.alpha()
0 Comments