Stage 1 · 15 minutes · Free
Python Basics: Print and Variables
Learn Python from zero: print your first line and store values in variables.
Objectives
- Use print() to print text and numbers to the screen
- Print many values on one line
- Write comments with #
Why learn this
Every program needs to show results to the user. print() is the simplest way for a program to 'talk' to you, and it is also the number-one tool for checking whether code is running correctly.
Concept
A Python program runs line by line, from top to bottom.
print(...) prints what is inside the parentheses. Text (strings) must be in quotes "..." or '...'. Numbers are written directly, with no quotes.
When you put many values in print, separated by commas, Python inserts one space between them.
A line starting with # is a comment: Python ignores it, it is only there so readers understand the code.
Syntax
print("text to print")
print(value_1, value_2)
# this is a comment
Example
# Chương trình đầu tiên
print("Xin chào Python")
print("Năm nay là", 2026)
print(3 + 4)Output:
Xin chào Python Năm nay là 2026 7
Line-by-line walkthrough
- Line 1: a comment, Python ignores it.
- Line 2: prints the string Xin chào Python.
- Line 3: prints two values, a string and a number; Python adds a space in between.
- Line 4: Python computes 3 + 4 first, then prints the result 7.
Common mistakes
print(Xin chào)Missing quotes, Python thinks Xin is a variable name and reports NameError or SyntaxError.
print("Xin chào")Print("Xin chào")Python is case-sensitive. Print is not print.
print("Xin chào")print("Xin chào"Missing closing parenthesis.
print("Xin chào")Summary
- print() prints values to the screen, one line per print call.
- Strings go in quotes, numbers do not.
- A comma inside print inserts one space.
- # starts a comment.
Write code right in the browser; the grader runs real Python and points to the exact wrong line.
Practice free