Home Tutorials Python Tutorial Input and Output
Input and Output

Input and Output


Definition: Input and Output (I/O) are the ways a program communicates with the user. Python uses the input() function to receive data from the user and the print() function to display data on the screen.

Why: Learning I/O is essential because it allows you to create interactive programs that can accept user information and provide results or feedback.

Syntax

  • variable = input("Prompt Message") - To get user input.
  • print(data_to_show) - To show output.

Example

name = input("Enter your name: ")
print("Hello,", name)

Explanation

  • The input() function pauses the program and waits for the user to type something.
  • The text inside the parentheses "Enter your name: " is shown as a prompt to the user.
  • The print() function takes the value stored in the variable and displays it along with the text "Hello,".

Key Notes

  • The input() function always reads data as **text (string)**.
  • If you want the user to enter a number for calculations, you must convert it using int() or float() (e.g., age = int(input("Enter age: "))).
  • You can print multiple items at once by separating them with a comma inside the print() function.
Example

🏋️ Test Yourself With Exercises

Take our quiz on Input and Output to test your knowledge.

Exercise »