SyntaxStudy
Sign Up
Python Beginner 6 min read

Input and Output

Input and Output in Python

print()

print("Hello")
print("a", "b", "c", sep="-")   # a-b-c
print("Hello", end=" ")          # no newline
print("World")

input()

name = input("Enter your name: ")
print(f"Hello, {name}!")

age = int(input("Enter your age: "))
print(f"You are {age} years old.")

Formatted Output

pi = 3.14159
print(f"Pi is approximately {pi:.2f}")
print("{:<10} {:>10}".format("left", "right"))
Pro Tip

input() always returns a string — cast it if you need a number.