In this tutorial, we will learn about python input() method and its uses with examples.
The python input() method allows users to take input and store the imputed value in a variable as a string.
The syntax of input() method is:
Python input() Method Parameters
The input() method takes only one optional argument:
- prompt (Optional) – a setting that represents a message before the input. (By default, it will take input as a string.
Let’s see the same example of the input() method in python.
Example 1: How to use the input() method in python?
Example 2: Input() method with prompt message.
The output will be as follow:
In the above program, we can see that when we run the program is returning a prompt, and in the same line, we can input the value, and after that, it is storing it in the user_Input variable.
The input() will automatically take input as a string, but we can use int() and float() to take input as in an integer and float.
You can also see an amazing python blog on How to send birthday wishes email with python to send birthday wishes to your family and friends.
Example 3: Taking input as integer and float in input() method.
The output will be as follows.
This is how you can take input from users into different data types.
Rules of input() method
- The input() method reads a line from the input (usually from the user), converts the line into a string by removing the trailing newline, and returns it.
- If EOF is read, it raises an EOFError exception.