Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on. You've got this! π
Your First Python Program
Write, save, and run your first Python program. Learn how Python executes code line by line and understand the basic structure of a Python script.
Creating a Python File
Python files have the .py extension. Create a file called hello.py, write your code inside, and run it from the terminal with 'python hello.py'. Python executes code from top to bottom, one line at a time.
Python reads your .py file top to bottom and runs each line immediately
Hello World Program
# Save this as hello.py
# Run with: python hello.py
print("Hello, World!")
print("Welcome to Python programming!")
print() # prints an empty line
# You can print multiple items
print("My name is", "Alice")
print("I am", 25, "years old")
# Escape characters
print("Line 1\nLine 2") # \n = new line
print("Tab\there") # \t = tab
print('He said "Hello!"') # quotes inside quotesTry It Yourself: My First Script
Tip
Tip
Use the print('=' * 30) trick to create visual separators in your output. It makes console output much more readable, especially when debugging multiple values.
Common Mistake
Warning
Forgetting that Python is case-sensitive. Print() with a capital P gives NameError. It must be print() with lowercase p. Same for all built-in functions.
Practice Task
Note
Build a business card printer: (1) Print your name, title, email in a formatted box. (2) Use escape characters \n and \t for formatting. (3) Use string multiplication for borders.