In python, by using input()
function you can read or get the user input. The input()
method will read the keystrokes and return them as a string object.
Generally, the python will pause the code execution when it reaches the input()
method and continues the code execution once it receives input from the user.
Following is the example of getting the user input using input()
function in python.
When you execute the above python program, the code execution will stop at the input()
function. Once the user enters the input value and clicks on Enter, the input()
method will read the user input and assign it to a name variable.
In python, the built-in print()
function is useful to display output to the user. By using the print()
function, you can display the output in different formats.
Following is the example of displaying the output to the user using the print()
function in python.
If you observe the above example, we are trying to display the output in different ways using print()
function.
When you execute the above python program, you will get the result as shown below.
In python, you can also format the user output by using format()
method based on your requirements.
When you execute the above python program, you will get the result as shown below.
To know more about formatting in python, refer python string format() method.
This is how you can get the user input and display it by formatting it based on your requirements.