Introduction to Python
Python is an interpreted, high-level programming language created by Guido van Rossum and first released in 1991. Its design philosophy emphasizes readability — often summarized as “There should be one obvious way to do it.” Today Python ranks among the top three languages worldwide.
What is Python?
Python is:
- Interpreted — code runs through the CPython interpreter (or alternatives like PyPy, Jython)
- High-level — memory management, file I/O, and networking are abstracted away
- Dynamically typed — variable types are determined at runtime
- Multi-paradigm — supports procedural, object-oriented, and functional styles
Python powers web backends, data science, machine learning, automation, DevOps scripting, and scientific computing.
History and Evolution
| Version | Year | Notable Changes |
|---|---|---|
| Python 1.0 | 1994 | Lambda, map, filter, reduce |
| Python 2.0 | 2000 | List comprehensions, garbage collection |
| Python 3.0 | 2008 | Unicode by default, print as function |
| Python 3.6 | 2016 | f-strings, variable annotations |
| Python 3.9 | 2020 | Dict merge operators, type hints |
| Python 3.11 | 2022 | Faster CPython, better tracebacks |
| Python 3.12 | 2023 | Improved error messages, typing |
Python 2 reached end of life in 2020. Always use Python 3 — currently 3.11 or 3.12 for new projects.
Key Features and Benefits
- Readability: Indentation defines blocks instead of braces; code reads like pseudocode.
- Batteries included: The standard library covers JSON, HTTP, SQLite, datetime, and more.
- Huge ecosystem: PyPI hosts 500,000+ third-party packages.
- Cross-platform: Runs on Windows, macOS, Linux, and embedded systems.
- Strong communities: Web (Django/Flask), data (pandas/numpy), ML (PyTorch/scikit-learn).
Your First Python Program
# hello.py
def greet(name: str) -> str:
return f"Hello, {name}!"
if __name__ == "__main__":
print(greet("Python"))
Run it:
python3 hello.py
# Hello, Python!
Interactive mode is great for experimentation:
python3
>>> 2 + 2
4
>>> [x ** 2 for x in range(5)]
[0, 1, 4, 9, 16]
Variables and Data Types
age = 30 # int
price = 19.99 # float
title = "GazeHub" # str
is_active = True # bool
tags = ["python", "web"] # list
user = {"id": 1, "name": "Alice"} # dict
# Type hints (optional but recommended)
def add(a: int, b: int) -> int:
return a + b
Control Flow Preview
scores = [85, 92, 78, 95, 88]
passed = [s for s in scores if s >= 80]
for score in passed:
print(f"Pass: {score}")
# Output:
# Pass: 85
# Pass: 92
# Pass: 95
# Pass: 88
Python vs Other Languages
Python vs Java: Python code is typically 3–5× shorter for the same task. Java offers stronger compile-time checking and higher raw throughput for CPU-bound server workloads. Python wins on developer speed and data tooling.
Python vs JavaScript: Both are dynamically typed. JavaScript dominates browsers; Python dominates data science and scripting. With Node.js, JavaScript also runs on servers — choose based on team skills and ecosystem.
Python vs C++: C++ gives manual memory control and maximum performance. Python trades speed for productivity. Use C++ for game engines and systems code; use Python for everything else unless profiling proves otherwise.
Common Application Areas
| Area | Libraries / Frameworks |
|---|---|
| Web development | Django, Flask, FastAPI |
| Data science | pandas, NumPy, Jupyter |
| Machine learning | scikit-learn, PyTorch, TensorFlow |
| Automation | argparse, pathlib, requests |
| DevOps | Ansible modules, boto3 (AWS) |
| Testing | pytest, unittest |
Setting Up Python
# macOS (Homebrew)
brew install [email protected]
# Verify
python3 --version
pip3 --version
# Create an isolated environment (recommended)
python3 -m venv .venv
source .venv/bin/activate # macOS/Linux
pip install requests
Use virtual environments for every project to avoid dependency conflicts. See Installing Python for full setup instructions.
The Zen of Python
import this
This prints guiding principles — among them: “Beautiful is better than ugly,” “Simple is better than complex,” and “Readability counts.”
What Comes Next
This track covers syntax, OOP, file handling, standard libraries, web frameworks, async programming, data science basics, packaging, and performance. Work through the pages sequentially to build a solid foundation and reach expert-level Python development.