input/output (I/O)

In programming, input/output (I/O) refers to the communication between a computer program and the outside world. This can involve reading data from a user, file, or external device (input), and sending data back to these entities (output).

In Python, input is any data that flows into your program:

  • User input from the keyboard
  • Data read from files
  • Network requests
  • Signals from hardware sensors

The most basic form of input in Python is the input() function, which pauses program execution and waits for the user to type something and press Enter.

Output is any data that flows out of your program to the external world:

  • Text printed to the screen
  • Data written to files
  • Network responses
  • Signals sent to hardware

Python provides built-in functions like input() for reading user input, print() for displaying output, and open() to read and write to files. Additionally, the Python standard library has modules like os, sys, and io to perform more advanced I/O operations, such as file manipulation and system interaction.

Example

Here’s an example illustrating basic input and output consisting of reading user input:

Python
>>> name = input("Enter your name: ")
Enter your name: Pythonista

>>> print(f"Hello, {name}!")
Hello, Pythonista!

In this example, the input() function waits for the user to type something and press Enter, capturing the input as a string. The print() function then outputs a greeting message, incorporating the user’s input.

Tutorial

Basic Input and Output in Python

In this tutorial, you'll learn how to take user input from the keyboard with the input() function and display output to the console with the print() function. You'll also use readline to improve the user experience when collecting input and to effectively format output.

basics python

For additional information on related topics, take a look at the following resources:


By Dan Bader and Leodanis Pozo Ramos • Updated April 16, 2025 • Reviewed by Leodanis Pozo Ramos