Why Learn Python?
Python is the world's most popular programming language
Used by Google, Netflix, Instagram, NASA, and thousands of companies. Python powers web apps, data science, AI, automation, and more.
Web Development
Django and Flask power millions of websites. Instagram serves 2+ billion users with Python.
Data Science & AI
NumPy, Pandas, TensorFlow, and PyTorch make Python the #1 language for data and ML.
Automation
From web scraping to DevOps scripts, Python automates tedious tasks in minutes.
Beginner Friendly
Clean syntax that reads like English. No semicolons, no curly braces.
Installing Python
Python comes pre-installed on macOS and most Linux distributions. Let's verify or set it up.
Check Your Current Version
Open a terminal and run:
python3 --version
Python 3.12.2
If you see version 3.8 or higher, you're ready. Otherwise, follow the steps below.
Install on macOS
# Using Homebrew (recommended)
brew install python3
# Verify
python3 --version
pip3 --version
Install on Ubuntu/Debian
sudo apt update
sudo apt install python3 python3-pip python3-venv
python3 --version
Install on Windows
Download Python
Go to python.org/downloads and download the latest Python 3.x installer.
Run the Installer
Check "Add Python to PATH" before clicking Install Now.
Verify
Open Command Prompt and type python --version to confirm.
Python 2 vs Python 3
Python 2 reached end-of-life on January 1, 2020. Always use Python 3. If your system has both, use python3 and pip3 explicitly.
The Python REPL
The REPL stands for Read-Eval-Print Loop. It's Python's interactive interpreter — think of it as a scratchpad where you can type Python code and see results instantly. No need to create a file, no need to run a command. Just type and get answers.
This is one of Python's greatest learning tools. Professional developers use it daily to test ideas, debug code, and explore libraries. You should have it open whenever you're coding.
Starting the REPL
Open your terminal (Terminal on Mac, Command Prompt on Windows, or any shell on Linux) and type python3:
$ python3
Python 3.12.2 (main, Feb 6 2024, 20:19:44)
Type "help", "copyright", "credits" for more information.
>>>
Try Some Expressions
The >>> prompt means Python is waiting for your input. Type any expression and press Enter — Python evaluates it immediately and shows the result. This instant feedback makes it perfect for learning:
>>> 2 + 3
5
>>> "Hello" + " " + "World"
'Hello World'
>>> len("Python")
6
>>> type(42)
>>> 2 ** 10
1024
Use It as a Calculator
Python makes an excellent calculator. Notice the difference between / (true division, always returns a decimal) and // (floor division, rounds down to a whole number). The ** operator is for exponentiation — much cleaner than calling a power function:
>>> 10 / 3 # True division (float result)
3.3333333333333335
>>> 10 // 3 # Floor division (integer result)
3
>>> 10 % 3 # Modulo (remainder)
1
>>> 2 ** 8 # Exponentiation
256
>>> abs(-42) # Absolute value
42
Type exit() or press Ctrl+D to leave the REPL.
Your First Python Program
The REPL is great for experiments, but real programs live in files. A Python file is just a plain text file with a .py extension. You write your code in it, save it, and run it from the terminal. Unlike compiled languages like Java or C++, there's no compilation step — Python reads and executes your file directly.
Let's create your first program. This is a rite of passage for every programmer — the classic "Hello, World!" — but we'll make it more interesting by also using variables and f-strings.
Create hello.py
Open your text editor (VS Code, PyCharm, or even Notepad) and create a new file called hello.py. Type the following code exactly as shown — pay attention to the indentation and quotation marks:
# hello.py
print("Hello, World!")
print("Welcome to Python!")
# Variables need no type declaration
name = "Pythonista"
age = 1 # days of experience
# f-strings for formatted output (Python 3.6+)
print(f"Hello, {name}!")
print(f"You have {age} day(s) of Python experience.")
print(f"By tomorrow, that will be {age + 1}!")
Run It
Save the file and go back to your terminal. Navigate to the folder where you saved hello.py and run it:
python3 hello.py
Hello, World! Welcome to Python! Hello, Pythonista! You have 1 day(s) of Python experience. By tomorrow, that will be 2!
Understanding the Code
Let's break down every line. Understanding what each piece does is more important than memorizing syntax — once you understand the concepts, the syntax becomes natural:
| Element | What It Does | Example |
|---|---|---|
# | Comment — ignored by Python | # This is a comment |
print() | Outputs text to the terminal | print("Hello") |
name = "..." | Creates a variable (no keyword needed) | name = "Alice" |
f"...{expr}..." | f-string — embeds expressions in strings | f"Hi, {name}" |
🔍 Deep Dive: Why No Semicolons or Braces?
Python uses indentation (4 spaces) instead of curly braces to define code blocks. This was a deliberate design choice to force clean, readable code. Lines end naturally — no semicolons needed. Indentation is part of the syntax, not just style.
Setting Up Your IDE
A good IDE makes Python development much more productive with autocomplete, debugging, and error highlighting.
VS Code (Recommended)
Install VS Code
Download from code.visualstudio.com
Install Python Extension
Extensions → Search "Python" → Install the Microsoft Python extension
Install Pylance
Also install Pylance for type checking and better autocomplete
Start coding
Create a .py file and you are ready to go!
Editor Comparison
| Editor | Best For | Free? |
|---|---|---|
| VS Code | General purpose, lightweight | Yes |
| PyCharm | Full Python IDE, debugging | Community: Yes |
| Jupyter Notebook | Data science, exploration | Yes |
| Sublime Text | Fast, minimal | Free trial |
| Vim/Neovim | Terminal users, speed | Yes |
The Python Philosophy
Python has guiding principles called "The Zen of Python":
>>> import this
Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Readability counts. ...
PEP 8 — The Style Guide
PEP 8 is Python's official style guide. Following it makes your code readable:
# snake_case for variables and functions
my_variable = 42
def calculate_total(items):
return sum(items)
# PascalCase for classes
class ShoppingCart:
pass
# UPPER_CASE for constants
MAX_RETRIES = 3
DEFAULT_TIMEOUT = 30
⚠️ Common Mistake: Using Python 2 Syntax
Wrong:
print "Hello, World!" # SyntaxError in Python 3!
raw_input("Name: ") # NameError in Python 3
Why: Python 3 made print a function and renamed raw_input to input.
Instead:
print("Hello, World!") # Python 3
input("Name: ") # Python 3
Next Steps
You've installed Python, explored the REPL, written your first program, and set up your IDE. Next: Variables & Data Types.
Practice
Modify hello.py — try different print statements, create more variables, experiment with f-strings.
Explore the REPL
Open python3 and try math operations, string methods, and type() on different values.
Bookmark This
Save this tutorial for quick reference as you continue learning.