What is Python?
Python is a high-level, interpreted programming language created by Guido van Rossum and first released in 1991. It emphasizes code readability and simplicity - its design philosophy is that there should be one obvious way to do things, and that code should be readable without needing extensive comments.
Python is dynamically typed (you do not declare variable types), garbage collected (memory is managed automatically), and supports multiple programming paradigms: procedural, object-oriented, and functional.
# Python is readable - this is nearly plain English
name = "Alice"
age = 30
if age >= 18:
print(f"{name} is an adult.")
else:
print(f"{name} is a minor.")
# No semicolons, no braces, no type declarations
# Indentation defines code blocks
Why Python is Popular
Python has been the most popular programming language in the TIOBE Index and Stack Overflow surveys for several years. Several factors drive this:
- Readable syntax - code is close to pseudocode, lowering the barrier to entry
- Huge standard library - "batteries included" means most common tasks have a built-in solution
- Massive ecosystem - PyPI hosts over 500,000 packages covering every domain
- Dominance in AI/ML - PyTorch, TensorFlow, scikit-learn, pandas, and NumPy are all Python-first
- Versatility - the same language works for quick scripts, web APIs, data pipelines, and research
- Community - large, welcoming community with extensive documentation and tutorials
Key Use Cases
| Domain | What Python does | Key libraries |
|---|---|---|
| Data Science | Data analysis, visualization, statistics | pandas, NumPy, matplotlib, seaborn |
| Machine Learning | Training models, inference, research | scikit-learn, PyTorch, TensorFlow, XGBoost |
| AI Applications | LLM apps, RAG, agents, embeddings | LangChain, LlamaIndex, openai, anthropic |
| Web Development | REST APIs, full-stack web apps | FastAPI, Django, Flask |
| Automation | Scripts, file processing, web scraping | requests, BeautifulSoup, Playwright, Selenium |
| DevOps | Infrastructure as code, CI/CD tools | Ansible, AWS CDK, Fabric |
| Finance | Quantitative analysis, algorithmic trading | zipline, backtrader, yfinance |
Python 3 vs Python 2
Python 2 reached end-of-life on January 1, 2020. All new code should use Python 3. The current stable series is Python 3.12 (as of 2024), with 3.13 in active development.
| Feature | Python 2 | Python 3 |
|---|---|---|
print "hello" (statement) | print("hello") (function) | |
| String default | bytes (ASCII) | Unicode (str) |
| Integer division | 5/2 = 2 | 5/2 = 2.5 |
| f-strings | Not available | Available from 3.6+ |
| async/await | Not available | Available from 3.5+ |
| Type hints | Not available | Available from 3.5+ |
| Support | EOL since 2020 | Active - use this |
How Python Works
Python is an interpreted language. When you run a .py file, CPython (the reference implementation) compiles it to bytecode (.pyc files), then the Python Virtual Machine executes that bytecode. This happens transparently - you never manually compile Python code.
# Write your code in a .py file
$ python hello.py # CPython compiles + runs it
$ python3 hello.py # On systems with both Python 2 and 3
# Or use the interactive REPL (Read-Eval-Print Loop)
$ python3
>>> 2 + 2
4
>>> print("Hello")
Hello
>>> exit()
CPython is the standard. Other implementations include PyPy (JIT-compiled, much faster for CPU-bound code), Jython (runs on JVM), and MicroPython (for microcontrollers). When people say "Python" they almost always mean CPython.
Python vs Other Languages
| Language | vs Python | When to prefer the other |
|---|---|---|
| JavaScript | Python is cleaner for scripting; JS required for browsers | Frontend web, Node.js server, React/Vue apps |
| Java/C# | Python is faster to write; Java/C# have stronger static typing | Enterprise systems, Android (Java), game dev (C#) |
| Go/Rust | Python is slower at runtime; Go/Rust are compiled and much faster | High-performance systems, CLI tools, microservices |
| R | Python has broader ecosystem; R has better built-in stats | Statistical research, academia, specific bioinformatics |
| SQL | Different tools - Python calls databases, SQL queries them | Data queries belong in SQL; use both together |
First Look at Python Code
# Variables - no type declarations needed
name = "Alice"
age = 30
height = 1.75
is_admin = True
# Lists (like arrays)
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # apple
print(fruits[-1]) # cherry (negative index)
# Dictionaries (key-value pairs)
user = {"name": "Alice", "age": 30}
print(user["name"]) # Alice
# Functions
def greet(person):
return f"Hello, {person}!"
print(greet("Bob")) # Hello, Bob!
# Classes
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
return f"{self.name} says woof!"
dog = Dog("Rex")
print(dog.bark()) # Rex says woof!
apple cherry Alice Hello, Bob! Rex says woof!
The fastest way to learn Python is to type examples directly into the Python REPL. Open a terminal and run python3. You can test any expression instantly without creating a file. Use it as a calculator, an experiment pad, and a quick reference throughout this tutorial.