← Back More Python posts Home

Python Input and Output: print(), input() and f-strings for Beginners

November 16, 2026

Every useful program talks to the user. It shows messages on the screen, and it asks questions. In Python, showing a message is called output, and taking an answer from the user is called input. In this guide, you will learn print(), input() and f-strings with simple examples. If you do not know variables yet, read Python Variables and Data Types first.

Python input and output explained
In this post, you will learn:
  • What input and output mean in Python
  • How to show messages with print(), and how to use sep and end
  • How to take answers from the user with input()
  • Why input() always gives text
  • How to make clean messages with f-strings

What Are Input and Output?

Input is the information that goes into your program, for example a name that the user types. Output is the information that your program shows, for example a message on the screen.

  • input() takes the input from the user.
  • print() shows the output on the screen.
What are input and output in Python

Step 1: Show Output with print()

  1. Open VS Code and open your python-practice folder.
  2. Click the New File icon and name the file output.py.
  3. Type the code below.
  4. Press Ctrl + S to save the file.
  5. Click the triangle (Play) button at the top right to run it.
print("Hello, world!")
print("My name is Ali")
print(2026)

You should see this output:

Hello, world!
My name is Ali
2026
Show output with print() in VS Code

Text must go inside quotes, like "Hello, world!". Numbers do not need quotes. Every print() shows its result on a new line.

Step 2: Print Many Things at Once

You can put many values inside one print(). Separate them with commas. Python puts one space between them.

print("Ali", "is", 20, "years old")

You should see this output:

Ali is 20 years old

Change the space with sep. The word sep means separator. It is what Python puts between the values:

print(2026, 11, 16, sep="-")

You should see this output:

2026-11-16

Stay on the same line with end. Normally, print() moves to a new line after it shows something. You can change this with end:

print("Hello", end=" ")
print("world")

You should see this output:

Hello world

Step 3: Take Input with input()

The input() function stops the program and waits for the user to type something. The text inside the brackets is the question that the user sees. The answer is saved in a variable.

  1. Create a new file named input.py.
  2. Type the code below and save it.
  3. Run it. A terminal opens at the bottom.
  4. Click in the terminal, type your name and press Enter.
name = input("Your name: ")
print("Hello,", name)

If you type Ali and press Enter, you will see this output:

Your name: Ali
Hello, Ali
Take input with input() in Python

Here, name is a variable. It keeps the answer of the user, so you can use it later.

Step 4: Input Is Always Text

This is the most important rule. The input() function always gives you text, even if the user types a number. So if the user types 20, Python sees it as "20", and you cannot do maths with it. This code gives an error:

age = input("Your age: ")
print(age + 1)

The error is TypeError: can only concatenate str (not "int") to str. To fix it, change the text into a number with int():

age = int(input("Your age: "))
print("Next year you will be", age + 1)

If you type 20, you will see this output:

Your age: 20
Next year you will be 21
Tip: Use int() for whole numbers like 20. Use float() for decimal numbers like 5.7.

Step 5: Make Clean Messages with f-strings

An f-string is the easiest way to put variables inside a message. Put the letter f before the first quote, and write the variable name inside curly brackets { }.

name = "Ali"
age = 20

print(f"My name is {name}")
print(f"I am {age} years old")

You should see this output:

My name is Ali
I am 20 years old
Python f-string example

You can also do maths inside the curly brackets. For example, print(f"Next year: {age + 1}") shows Next year: 21.

Remember: if you forget the f, Python will show {name} as normal text.

Step 6: Practice Program

Now let us use everything together. Create a new file named greeting.py and type this:

name = input("Your name: ")
age = int(input("Your age: "))

print(f"Hello, {name}!")
print(f"Next year: {age + 1}")

If you type Ali and 20, you will see this output:

Your name: Ali
Your age: 20
Hello, Ali!
Next year: 21
Python input and output practice program

Now run it again with your own name and age. This is the best way to learn.

Common Errors and How to Fix Them

Error 1: SyntaxError: unterminated string literal

You forgot to close a quote. For example:

print("Hello)

The text starts with a quote but does not end with one. Write print("Hello") instead. The same error type happens when you forget a closing bracket.

Error 2: NameError: name 'hello' is not defined

You forgot the quotes around text:

print(hello)

Python thinks hello is a variable. To show the word, write print("hello").

Error 3: TypeError: can only concatenate str (not "int") to str

You tried to do maths with the text from input(). Change it into a number first:

age = int(input("Your age: "))

Error 4: ValueError: invalid literal for int()

The user typed letters, but your code wanted a number. For example, int("abc") will fail. Type only digits like 20 when the program asks for a number.

Common Mistakes Beginners Make

  • Forgetting the quotes around text. Write print("Hello"), not print(Hello).
  • Forgetting the brackets. In Python 3, write print("Hello"), not print "Hello".
  • Forgetting that input() gives text. Use int() before doing maths.
  • Forgetting the f in an f-string. Without it, Python shows {name} as it is.
  • Using different quotes at the start and the end. Do not write "Hello'. Use the same quote on both sides.
  • Forgetting to save the file. Press Ctrl + S before you run the code.

Practice Time

Try these small tasks on your own. Click a question to open the code box, write your Python code and press Run. If your code is correct, you will see a green message. If there is an error, you will see the error, the line number, the mistake and how to fix it.

  1. Print two lines of text with print().
  2. Print 2026, 11 and 16 on one line with a dash between them.
  3. Ask for the user's name with input() and greet the user.
  4. Ask for the user's age and print the age next year.

What to Learn Next

Now you know how to show messages and take answers from the user. The next step is conditions. You will learn how to make decisions in your program with if, elif and else. In the next post, we will learn them with simple examples. If you missed the full learning plan, read my Python roadmap for beginners.

Frequently Asked Questions (FAQs)

What is the difference between print() and input()?

print() shows a message on the screen (output). input() waits for the user to type something and gives it to your program (input).

Why does input() always give text?

Python cannot know if the user will type a name or a number, so it keeps everything as text. If you need a number, change it with int() or float().

What is an f-string?

An f-string is a text with the letter f before the first quote. It lets you put variables inside curly brackets, like f"Hello, {name}!".

What do sep and end do in print()?

sep changes what goes between the values, and end changes what goes at the end of the line. By default, they are a space and a new line.

Final Thoughts

Input and output make your programs feel alive. Remember the three big ideas: print() shows output, input() takes input, and input() always gives text. Practice a little every day, and try to change the messages in the examples to see what happens.

Enjoyed this post? Keep learning with more tutorials

← Back More Python posts All Categories

Comments

← Back