On this page

Input and Output

Published on August 17, 2026

Enrico Hochkoeppler Profile

By Enrico Hochkoeppler

Web Developer & TutoriaLibre Founder

What Input and Output Are​

Input and output are the primary ways a program communicates with the outside world. Input is data that comes into the program, usually from the user. Output is information the program sends out, typically to the screen. Almost every useful Python program relies on both.

Python provides built‑in functions for input and output that are simple to use and consistent across platforms. Understanding these functions is essential for writing interactive scripts.

Output with print()​

The print() function displays information on the screen. It accepts one or more values and converts them into text.


print("Hello, world!")

print(42)

print("The result is:", 10 + 5)

By default, print() adds a newline at the end of the output, so each call appears on a new line.

Multiple Values and Separators​

When you pass multiple arguments to print(), Python inserts a space between them.


name = "Alice"

score = 95

print(name, "scored", score)

You can control the separator and the ending using the sep and end parameters:


print("A", "B", "C", sep="-")      # A-B-C

print("Line 1", end="...")

print("Line 2")

These options become important when you need precise formatting.

Input with input()​

The input() function reads a line of text from the user and returns it as a string.


name = input("Enter your name: ")

print("Hello,", name)

The text inside input() is the prompt. It appears before the user types anything and helps them understand what is expected.

Converting Input to Numbers​

Because input() always returns a string, you must convert the result when you need a number.


age_text = input("Enter your age: ")

age = int(age_text)

print("Next year you will be", age + 1)

For decimal numbers, use float():


price_text = input("Enter the price: ")

price = float(price_text)

print("Price with tax:", price * 1.1)

If the user types something that cannot be converted, Python raises an error. Handling such errors will be covered in a later lesson.

Combining Input and Output​

Interactive programs typically follow a simple pattern:

  1. Ask the user for input
  2. Convert and process the input
  3. Display the result

x = int(input("Enter a number: "))

y = int(input("Enter another number: "))

print("Their sum is:", x + y)

This pattern appears in calculators, configuration tools, and many automation scripts.

How Input Affects Program Flow​

When a program reaches an input() call, execution pauses until the user provides data and presses Enter. Only then does the program continue.


print("Start")

value = input("Type something: ")

print("You typed:", value)

print("End")

Understanding this pause is important when designing programs that depend on user interaction.

Why Input and Output Matter​

Input and output transform a static script into an interactive program. They allow your Python code to respond to user choices, gather data, and present meaningful results. Mastering these basic mechanisms is essential before moving on to more advanced topics such as control flow, functions, and data structures.

Found this helpful? Share the knowledge...

... or support this project to keep it alive!

Buy Me a Coffee

Previous

Variables and Data Types

Next

Operators and Expressions