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.
Everything in Python is an object — use type() to check
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.