In this post we will be creating a Python script that will check for string types. Checking the string types in the following examples will return a true or false.
This of course will be dependant on the the string and there many types one can check for.
For example if we are wanting to know whether our string is a number (Non negative) we would use the following.
string = "9"
print(string.isdigit())
#Returns True
If we are wanting to check whether all characters in our string are alphabetic, we would use the following.
string = "Hello"
print(string.isalpha())
#Returns True
If we are wanting to check whether characters in our string are alphanumeric, we would us the following.
string = "Hello123"
print(string.isalnum())
#Returns True
If we are wanting to check whether all characters in our string are all lower case, we would us the following.
string = "hello"
print(string.islower())
#Returns True
If we are wanting to check whether all characters in our string are all upper case, we would us the following.
string = "HELLO"
print(string.isupper())
#Returns True
If you have enjoyed our post about python string types, why not take a look at some of our other content around the Python programming language here.