Skip to main content
Albero Academy

Input & Output

Read from the user with input() and display results with print() and f-strings.

Fundamentals9 min

Programs talk to people. print() sends output to the screen; input() reads a line the user types. Together they make your first interactive scripts.

input and print
name = input("What's your name? ") # always returns a STRING
print("Hello,", name)
# input is always a string — convert when you need a number
age = int(input("Your age? "))
print(f"Next year you'll be {age + 1}")
# print options
print("a", "b", "c", sep="-") # a-b-c
print("no newline", end=" ") # keeps the cursor on the same line

Key takeaways

  1. 01print() displays output; use sep and end to control formatting.
  2. 02input() reads a line and always returns a string.
  3. 03Convert input with int()/float() when you need a number.
  4. 04f-strings are the cleanest way to build output from values.

Finished this chapter?

Mark it complete to track your progress through Python.