Your First Python Program
Write, understand, and run your very first Python code.
Every program communicates. print() is Python's built-in way to send output to the screen — no imports, no setup, always available.
It's the first function every Python developer learns and the one they use most often: debugging, logging, showing results. Let's see what it can do.
print() is flexible. Give it one value, many values, or expressions:
print('Hello') # Hello
print('Score:', 42) # Score: 42
print(10 + 5) # 15 ← expression evaluated first
print('a', 'b', 'c') # a b c ← values joined with spaceKey insight: when you pass multiple arguments separated by commas, Python evaluates each one, then joins them with a space automatically.
What does this print?
print('Year:', 2024 - 33)- AYear: 2024 - 33
- BYear: 1991
- CYear:1991
- DError
Two optional parameters control print's output format:
# sep: what goes BETWEEN values (default: a space)
print('2024', '01', '15', sep='/') # 2024/01/15
print('a', 'b', 'c', sep=' | ') # a | b | c
# end: what goes AFTER all values (default: newline)
print('Loading', end='...') # Loading...
print('done!') # done! ← continues right after
# Full output: Loading...done!What is the complete output of these two lines?
print("A", "B", sep="+")
print("C")- AA+B C
- BA B C
- CA+B C
- DA+BC
You want two print() calls to appear on the same line. Which parameter do you change?
- Asep=''
- Bend=''
- Cnewline=False
- Dinline=True
Comments are notes Python ignores completely:
# This entire line is a comment
birth_year = 1991 # inline comment
age = 2024 - birth_year # 33A good comment explains why a decision was made, not what the code does. The code already shows what it does.
# add 1 to x on x += 1 adds no value. # offset by 1 for 1-indexed display explains a non-obvious choice.Make these two prints appear on the SAME LINE:
print('Loading', ___='')
print('done!')