String Checking

In Python, we can check strings if we they contain few characters. These characters can include numbers, lower case, upper case, both numbers and alphabets. To achieve this, we use:

string.isCondition() 

(1) Check if the string contain numbers

string.isdigit()

This function lets us to check if a string contains numbers.

>>>'123'.isdigit()
True

Because the string 'ABC123' has numbers, which are 123, this function returns us with a boolean operator called, 'True' conveying that there are numbers in the string.

(2) Check for lower or upper case alphabets

In the same way, we can check if all the characters in the string are upper or lower case.

>>> 'abc'.islower() 
True 
>>> 'ABC'.isupper() 
True

(3) Check if all the characters in the string are alphabets

Using string.isalpha() to check if the string contains all alphabets and we can use string.isalnum() to check if the string contains a combination of letters and numbers.

>>> 'abC'.isalpha()
True 
>>> 'aBc123'.isalnum() 
True