Print Statements
What It Is
The print() function displays output to the screen. Whatever you put inside the parentheses will appear in the terminal when you run your code.
Why We Use It
Print statements let you:
- See results of your code
- Display information to users
- Debug problems by showing what's happening at each step
- Create formatted output like stat cards, reports, or leaderboards
Every sports graphic you see on TV — scores, player stats, standings — is essentially printed output, just with fancier styling.
How to Use It
Basic Print
print("Hello, sports fans!")
Output:
Hello, sports fans!
Printing Variables
player = "Simone Biles"
medals = 37
print(player)
print(medals)
Output:
Simone Biles
37
Combining Text and Variables with F-Strings
F-strings (formatted strings) let you mix text and variables easily. Put an f before the quotes, and wrap variable names in curly braces {}:
player = "Simone Biles"
medals = 37
print(f"{player} has won {medals} World and Olympic medals!")
Output:
Simone Biles has won 37 World and Olympic medals!
Multiple Print Statements
Each print() creates a new line:
print("=== STAT CARD ===")
print("Player: Wilt Chamberlain")
print("Points: 100")
print("Date: March 2, 1962")
print("=================")
Output:
=== STAT CARD ===
Player: Wilt Chamberlain
Points: 100
Date: March 2, 1962
=================
Blank Lines
Use print() with nothing inside to create a blank line:
print("First section")
print()
print("Second section (with space above)")
Output:
First section
Second section (with space above)
Formatting Tips
Building a Stat Card
player = "Joe DiMaggio"
achievement = "56-game hitting streak"
year = 1941
team = "New York Yankees"
print("╔══════════════════════════════════════╗")
print(f" {player}")
print(f" {team}")
print("──────────────────────────────────────")
print(f" Achievement: {achievement}")
print(f" Year: {year}")
print("╚══════════════════════════════════════╝")
Output:
╔══════════════════════════════════════╗
Joe DiMaggio
New York Yankees
──────────────────────────────────────
Achievement: 56-game hitting streak
Year: 1941
╚══════════════════════════════════════╝
Using Special Characters
You can use symbols to make your output look better:
print("★ MVP Season Stats ★")
print("━" * 30) # Prints the ━ character 30 times
print("Points: 2,818")
Output:
★ MVP Season Stats ★
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Points: 2,818
Common Patterns
Print with calculation
You can do math right inside the curly braces {} of an f-string. Python calculates the result and shows it in your output. Here are the basic math operators you can use:
+for addition-for subtraction*for multiplication/for division
Calculating points per game:
points = 100
games = 1
print(f"Points per game: {points / games}")
Output:
Points per game: 100.0
Calculating win percentage:
wins = 12
total_games = 16
print(f"Win percentage: {wins / total_games * 100}%")
Output:
Win percentage: 75.0%
Adding up total points:
touchdowns = 3
field_goals = 2
print(f"Total points: {touchdowns * 6 + field_goals * 3}")
Output:
Total points: 24
Calculating batting average:
hits = 45
at_bats = 150
print(f"Batting average: {hits / at_bats:.3f}") #.3f formats the number with 3 digits after the decimal points
Output:
Batting average: 0.300
Print multiple values
player = "Lionel Messi"
goals = 8
tournament = "2022 World Cup"
print(player, "-", goals, "goals at", tournament)
Output:
Lionel Messi - 8 goals at 2022 World Cup
Common Pitfalls
| Problem | What Went Wrong | Fix |
|---|---|---|
SyntaxError: unterminated string | Forgot closing quote | Add the missing " at the end |
NameError: name 'player' is not defined | Variable doesn't exist | Create the variable before printing it |
Curly braces showing literally {player} | Forgot the f before the string | Change "{player}" to f"{player}" |
| Extra spaces or weird formatting | Spaces inside your string | Check what's between your quotes |
Quick Reference
# Basic print
print("Hello!")
# Print a variable
print(player_name)
# F-string (text + variables)
print(f"{player} scored {points} points")
# Multiple values with commas
print("Score:", home, "-", away)
# Blank line
print()
# Repeat a character
print("=" * 20) # Prints: ====================