When dealing with strings, it’s also important to check if some conditions hold. Below are several popular methods that are used to check for some conditions in a string:
Check if all the letters are uppercase
Check if all the letters are lowercase
Check if all the words start with uppercase and are followed by lowercase letters
Checks if all the characters are numbers
Checks if all the characters are alphabetical
Checks if all the characters are either alphabetical or numeric
Check if the string starts with
Check if the string ends with
Checks if all the characters are whitespace characters (
Bear in mind that memorizing these methods is not necessary. Despite the names being very intuitive, a short googling will lead you to the method you actually need. This small table is just a fraction of the useful methods to demonstrate what is possible with a single line of Python code.
Note that string does not have
contains()method as there is already an
inkeyword present which checks if one string is contained in another.
Given a string, count the number of uppercase, the number of lowercase, and the number of space letters.
The input contains a single line of text which needs to be analyzed.
The program should print a single line with 3 numbers - the number of uppercase letters, the number of lowercase letters, and the number of space letters.
Hey, how are you doing today Anna?
2 24 6
Amazing job with the infrastructure setup Bob!
2 37 6