In this tutorial, we will learn how to make user input uppercase in Python. Learning how to manipulate user input and textual data is essential when it comes to working with strings in any programming language.
We will focus on Python here as it’s a popular choice for beginners and experts alike. We will also see various methods to transform user input into uppercase using different Python functions.
Step 1: Take User Input
Firstly, we need to take input from the user. Python provides a simple way to achieve this using the input()
function. Here is a simple example of how to take input from the user:
1 |
user_input = input("Enter some text: ") |
The above line of code will print “Enter some text: ” on the console and wait for the user to provide some input. After the user has entered the text and pressed ‘Enter’, the input will be stored in the user_input
variable.
Step 2: Transform the Input into Uppercase
Python provides various built-in methods to transform strings. In this tutorial, we will be using the upper()
method. The upper()
method is called on a string and returns a new string, with all the characters in uppercase. Let’s see how to use it:
1 |
uppercase_input = user_input.upper() |
In the above line of code, we have called the upper()
method on the user_input variable, which will return the uppercase version of the input. We then store that in the uppercase_input
variable.
Step 3: Print the Result
Now, that we have the uppercase input, we can print it to the console using the print()
function. Here’s how to do it:
1 |
print("Your input in uppercase: ", uppercase_input) |
The above line will print the following output on the console:
Your input in uppercase: [UPPERCASE_INPUT]
Now that we are familiar with all the steps, let’s put everything together.
Full Code
1 2 3 |
user_input = input("Enter some text: ") uppercase_input = user_input.upper() print("Your input in uppercase: ", uppercase_input) |
Sample Output
Enter some text: hello, world! Your input in uppercase: HELLO, WORLD!
Conclusion
In this tutorial, we learned how to take input from the user in Python, transform it into uppercase using the upper()
method, and print the result.
This is a simple example of how you can manipulate textual data in Python. There are various other built-in methods available in Python that can help you work with strings.
You can refer to the official Python documentation for more information on string methods.