How To Let Python Recognize Both Lower And Upper Case Input

In this tutorial, we will learn how to make Python recognize the user’s input, whether it is in lower or upper case.

When it comes to handling user input, it is often necessary to accept inputs in various text cases to improve the user experience and provide flexibility. This will help your Python program work smoothly, regardless of the case sensitivity of user input.

Step 1: Accept User Input

First, let’s write a simple Python code to accept user input. The input() function can be used to get the user’s input, and we will store that input in a variable named user_input.

Step 2: Convert User Input To Lowercase

Now, to make Python recognize both lower case and upper case input, we need to convert the user input to either all lower case or all upper case. In our tutorial, we will convert the user input to lowercase using the lower() function. This function is available for strings in Python and returns a copy of the string with all the characters in lowercase.

After converting the user input to lowercase, you can now run any comparisons, checks, or searches on the input without worrying about case sensitivity.

Step 3: Process User Input

In this step, you can process the user input as per your desired functionality. For example, let’s say we want to check if the word “python” is present in the user’s input. We will simply use the in keyword in an if statement to check the presence of the word “python”.

Full Code:

Example Input and Output

Input: I love coding in Python!
Output: You've mentioned Python!

Input: My favorite programming language is PYTHON.
Output: You've mentioned Python!

Input: Have you heard of the PytHon programming language?
Output: You've mentioned Python!

Input: I am learning Java and JavaScript.
Output: No mention of Python found.

Conclusion

In this tutorial, we learned how to let Python recognize both lower case and upper case inputs by converting the user input to lowercase using the lower() function. This method ensures that your program works smoothly with case-insensitive input, allowing for greater flexibility and user experience.