๐Ÿ“ Python

Python's print() and input() Functions: Output and Input ๐Ÿ’ฌ

P
Author
PyLand Team
๐Ÿ“…
Published
30.03.2026
โฑ๏ธ
Reading time
5 min
๐Ÿ‘๏ธ
Views
456
๐ŸŒฑ
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!

You can run code in a local terminal, an IDE, or a browser sandbox. The output area name and location depend on the tool: look for Console, Terminal, or Output. Use its label rather than relying on panel color or position.

๐Ÿ–จ๏ธ The print() function โ€” display text

Basic usage

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

Multiline text and triple quotes

Text spanning several lines can be written between triple single ''' or triple double """ quotes:

message = """First line
Second line
Third line"""

print(message)

The opening and closing quote styles must match. Newlines and spaces inside the string are preserved.

For multiline text containing backslashes, a raw string is convenient. Add r before the opening quotes:

folders = r"""project\code
project\data
project\tests
"""

print(folders)

A raw string does not turn backslashes into escape sequences. It still cannot end with an odd number of backslashes immediately before the closing quotes.

When to use an r-string

The r prefix is useful when text contains many backslashes:

# Regular string: every backslash must be escaped
windows_path = 'C:\\Users\\student\\project'

# Raw string: backslashes are preserved
windows_path = r'C:\Users\student\project'

print(windows_path)

Raw strings are also convenient for ASCII art and regular-expression patterns. r changes backslash processing, but it does not remove quote rules. If the text contains double quotes, it is convenient to delimit the string with single quotes:

quote = r'They said: "Hello"'

Do not add r to every string automatically. Use a regular string for ordinary text, an f-string for value substitution, and a raw string when backslashes must be preserved.

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 โ€” an unclosed string or parenthesis

# โŒ Missing closing parenthesis
print('Hello'  # Error!

# โœ… Close the parenthesis
print('Hello')

Error 2: NameError โ€” Python treats text as a name

# โŒ No quotes: Python looks for a variable named Hello
print(Hello)

# โœ… Text is wrapped in quotes
print('Hello')

# โŒ Incorrect function-name capitalization
Print('Hi')

# โœ… Names are case-sensitive
print('Hi')

Error 3: 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 4: 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

๐Ÿ“

if __name__ == "__main__": the Python entry point

The if name == "main" guard defines a Python program's entry point: it distinguishes direct...

๐Ÿ“… 14.08.2026 ๐Ÿ‘๏ธ 44
๐Ÿ“

strip() and lower(): Preparing User Text ๐Ÿงน

A user may enter the correct word with extra spaces or different letter case. Python...

๐Ÿ“… 11.08.2026 ๐Ÿ‘๏ธ 50
๐Ÿ“

ord(), chr(), and Cyclic Letter Shifts in Python ๐Ÿ”

A string contains characters, but a computer stores every character as a numeric code. Python...

๐Ÿ“… 09.08.2026 ๐Ÿ‘๏ธ 89