Write your very first Python program and understand what's happening when you run it.
- The
print()function - Strings (text in quotes)
- How Python runs your code top-to-bottom
- Comments
- None — this is the very beginning!
Every programming journey starts the same way — printing something to the screen. In Python, that looks like this:
print("Hello, World!")That's it. One line. When you run this, Python will display:
Hello, World!
Let's break it down:
printis a built-in function. It tells Python "display this on the screen." You'll use it constantly.(and)are parentheses. They wrap what you're passing to the function — this is called an "argument.""Hello, World!"is a string — a piece of text. The quotes tell Python "this is text, not code." You can use either double quotes"or single quotes'— both work the same way.
You can pass multiple items to print(), separated by commas. Python will add a space between each one:
print("Hello", "World") # Output: Hello World
print("I", "love", "Python") # Output: I love PythonSee that # symbol? Anything after # on a line is a comment. Python ignores it completely — it's just a note for humans reading the code.
# This is a comment — Python skips this line entirely
print("This runs") # Comments can go at the end of a line tooUse comments to explain why you're doing something, not what you're doing. The code itself should be clear enough to show what's happening.
Python doesn't care about blank lines between statements. Use them to organize your code and make it readable:
print("Section 1")
print("Still section 1")
print("Section 2 — notice the blank line above for readability")Sometimes you need to include characters that have special meaning. Use a backslash \ to "escape" them:
print("She said \"hello\"") # Output: She said "hello"
print("Line 1\nLine 2") # \n creates a new line
print("Tab\there") # \t creates a tabOr just use the other type of quote to avoid escaping:
print('She said "hello"') # Single quotes outside, double inside
print("It's easy") # Double quotes outside, single insideprint() has a few handy tricks:
# Change what goes between items (default is a space)
print("2025", "02", "09", sep="-") # Output: 2025-02-09
# Change what goes at the end (default is a newline)
print("Loading", end="...")
print("Done!") # Output: Loading...Done!
# Print an empty line
print()Check out example.py for a complete working example that demonstrates everything above.
Try the practice problems in exercises.py to test your understanding.
print()displays text on the screen- Strings are text wrapped in quotes (single or double — your choice)
- Comments start with
#and are ignored by Python - Python runs your code from top to bottom, one line at a time
print()supportssepandendparameters for formatting control