In this tutorial, we will learn about the python input and output functions.
The input function is used to input the user and store it into variables. Input function can store a string or a numeric value.
The Input function can be defined with the input() function.
Syntax for input:
Syntax of output:
As we can see in the above syntax, first, we declare a variable, then assign the input function to that variable, and in between brackets, we add a string as a message which will be print when we run the program. By default, I will store all the given values in a String. If we want to take value in integer, we need to use int() function and float, and we need to use float() function.
Let run it one more time and use string as an input.
As you can see, we don’t need to specify any data type in the input function; it will store what every user has given.
Here we ask the user to enter a number, and then the input function is storing it in a variable as an integer using the int() function.
Here we are storing a value into a float.
How the input function works in Python:
- When the input() function is called at the time of the program’s execution, it will stop the program’s flow until the user has given any input in a string or numerical.
- The text or message displayed on the output screen to ask a user to enter the input value is optional, i.e., the prompt printed on the screen is optional.
- Whatever you enter as input, the input function converts it into a string. If you enter an integer value, the still input() function converts it into a string.
As we can see here, we have used two input functions, and we can use as many as we need.
Operations using the input function
We can also do different operations using operators like Addition, substation, and many more.
Let take an example with the python operator.
In the same way, we can also create our calculator program using python.
We hope you have learned about what python input output function is.