📝 Python

Python's print() and input() Functions: Output and Input 💬

0
Author
04e5cc8b-58ac-4bdc-bdee-661bbb
📅
Published
30.03.2026
⏱️
Reading time
3 min
👁️
Views
139
🌱
Level
Beginner

The two most essential functions for beginner Python developers! print() displays information on screen, and input() reads data from the user. Together they make programs interactive!

🖨️ The print() function — display text

Basic usage

print('Hello, world!')
print("Python is easy!")
print('You can use "double" quotes inside single ones')

Printing multiple values

name = 'Alex'
age = 16

# Comma-separated — spaces are added automatically
print('My name is', name, 'and I am', age, 'years old')
# Output: My name is Alex and I am 16 years old

Printing variables of different types

name = 'Maria'
age = 20
height = 1.65
is_student = True

print(name)        # Maria
print(age)         # 20
print(height)      # 1.65
print(is_student)  # True

f-strings — the modern way

name = 'Maxim'
age = 18

# f-string — cleaner and more convenient!
print(f'Hi, {name}! You are {age} years old.')
print(f'In a year you will be {age + 1}')
print(f'One minute = {60} seconds, one hour = {60 * 60} seconds')

Controlling output

# By default print() adds a newline
print('First line')
print('Second line')

# No newline at the end
print('Hello', end=' ')
print('world!')  # Output: Hello world!

# Blank line
print()  # Just a newline

# Custom separator
print('apple', 'banana', 'orange', sep=', ')
# Output: apple, banana, orange

📥 The input() function — reading user input

Basic usage

# The program pauses and waits for input
name = input('What is your name? ')
print(f'Hi, {name}!')

Important! input() ALWAYS returns a string (str)!

Type conversion

# ❌ Wrong — we get a string
age = input('How old are you? ')
print(age + 5)  # Error! Can't add a string and a number

# ✅ Correct — convert to a number
age = int(input('How old are you? '))
print(f'In 5 years you will be {age + 5}')

# For decimal numbers
height = float(input('Your height in meters: '))
print(f'Your height: {height} m')

An interactive program

print('=== BMI Calculator ===')

# Collect data
weight = float(input('Enter your weight (kg): '))
height = float(input('Enter your height (m): '))

# Calculate
bmi = weight / (height ** 2)

# Display result
print(f'\nYour BMI: {bmi:.1f}')

if bmi < 18.5:
    print('Underweight')
elif bmi < 25:
    print('Normal weight')
else:
    print('Overweight')

🎯 Common errors and fixes

Error 1: SyntaxError with print()

# ❌ Missing quotes
print(Hello)  # Error!

# ✅ Add quotes
print('Hello')

# ❌ Missing closing parenthesis
print('Hello'  # Error!

# ✅ Close the parenthesis
print('Hello')

# ❌ Wrong capitalization
Print('Hi')  # Error! Must be lowercase p

Error 2: TypeError when adding

# ❌ Adding a string and a number
age = input('Age: ')  # This is a string!
print(age + 5)  # TypeError!

# ✅ Convert to int first
age = int(input('Age: '))
print(age + 5)  # Works!

Error 3: ValueError

# If the user types text instead of a number
age = int(input('Age: '))
# Entered "abc" → ValueError!

# For now, just warn the user
print('Please enter a NUMBER!')

💡 Useful examples

Greeting

print('👋 Welcome!')
name = input('What is your name? ')
hobby = input('What are your hobbies? ')

print(f'\nNice to meet you, {name}!')
print(f'{hobby} — that is awesome! 🎉')

Simple quiz

print('=== Python Quiz ===\n')

score = 0

answer = input('What does print(2 + 2) output? ')
if answer == '4':
    print('✅ Correct!\n')
    score += 1
else:
    print('❌ Wrong, the answer is: 4\n')

answer = input('True or False — Python is case-sensitive? ')
if answer.lower() == 'true':
    print('✅ Correct!\n')
    score += 1
else:
    print('❌ Wrong, the answer is: True\n')

print(f'Your score: {score}/2')

Currency converter

print('💰 Currency Converter (USD → EUR)\n')

rate = 0.92  # USD to EUR exchange rate
dollars = float(input('Enter the amount in dollars: '))

euros = dollars * rate

print(f'\n${dollars} = €{euros:.2f}')

📋 Cheat sheet

# Output
print('text')                    # Simple output
print(variable)                  # Print a variable
print('a', 'b', 'c')             # Multiple values
print(f'x = {x}')               # f-string
print('text', end='')           # No newline
print()                          # Blank line

# Input
text = input('Question: ')       # Read a string
number = int(input('Number: '))  # Read an integer
decimal = float(input('Decimal: '))  # Read a float

# Type conversions
str(123)     # '123'  (number → string)
int('456')   # 456    (string → integer)
float('1.5') # 1.5   (string → float)

🚀 Practice

Try building:
1. A survey — collect name, age, city, hobbies
2. A calculator — two numbers and an operation
3. A story generator — ask for words and build a narrative
4. A converter — Celsius to Fahrenheit

🎓 Summary

  • print() — displays information on screen
  • input() — reads data from the user (always returns a string!)
  • f-strings — a convenient way to embed variables in text
  • int() / float() — convert strings to numbers

With these two functions you can build interactive programs! 💪

Your reaction to the article

💬 Comments (0)

🔐 Sign in to leave a comment
🚪 Login
💭

No comments yet

Be the first to share your opinion about this article!

🔗 Similar

Similar articles

Continue learning with these materials

📝

Setting Up Your Environment: Python, pip, and VS …

Before writing code locally, you need to set up three tools: Python, pip, and VS...

📅 04.06.2026 👁️ 16
📝

The datetime Module: Working with Dates and Times

datetime is Python's standard module for working with dates and times. It's part of the...

📅 08.05.2026 👁️ 66
📝

.env Files and Environment Variables: Keeping Sec…

Imagine you wrote a program with an API key hardcoded in the source and pushed...

📅 08.05.2026 👁️ 75

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!