In Python, Using the input() function, we take input from a user, and using the print() function, we display output on the screen. Using the input() function, users can give any information to the application in the strings or numbers format.
After reading this article, you will learn:
- Input and output in Python
- How to get input from the user, files, and display output on the screen, console, or write it into the file.
- Take integer, float, character, and string input from a user.
- Convert the user input to a different data type.
- Command-line input
- How to format output.
Table of contents
Python Input() function
In Python 3, we have the following two built-in functions to handle input from a user and system.
input(prompt): To accept input from a user.print(): To display output on the console/screen.
In Python 2,we can use the following two functions:
input([prompt])raw_input([prompt])
The input() function reads a line entered on a console or screen by an input device such as a keyboard, converts it into a string. As a new developer, It is essential to understand what is input in Python.
What is the input?
The input is a value provided by the system or user. For example, suppose you want to calculate the addition of two numbers on the calculator, you need to provide two numbers to the calculator. In that case, those two number is nothing but an input provided by the user to a calculator program.