Python 2 is obsolete as of January 2020. All modern DevOps automation uses Python 3 (specifically 3.8+). If you see references to Python 2, ignore them—this course targets Python 3.10+, the current standard.
What is Python & Why DevOps Uses It
Understand Python as a language, why it dominates infrastructure automation, and how it compares to Bash scripting and other tools. Get your first script running.
🧒 Simple Explanation (ELI5)
Imagine building a house. Bash is like using only the most basic tools—a hammer, nails, and rope. Python is like going to a hardware store and having access to power tools, measuring devices, and pre-cut materials. Both can build a house, but Python makes complex tasks easier and faster. DevOps engineers use Python because infrastructure tasks are complex—and Python gives them powerful tools to manage servers, run commands, parse logs, and interact with cloud APIs without writing hundreds of lines of code.
🔧 Why Do We Need Python for DevOps?
- Readability: code written in Python reads almost like English, making it maintainable by teams.
- Rich ecosystem: thousands of libraries for every DevOps task (Azure SDK, Kubernetes client, requests for APIs, paramiko for SSH).
- Cross-platform: the same Python script runs on Linux, macOS, and Windows without modification.
- Integration: Ansible (infrastructure automation), cloud CLIs, CI/CD systems all use Python under the hood.
- Learning curve: developers and operators can learn Python quickly and move between roles without context switching.
⚙️ Technical Explanation
Python is an interpreted, dynamically-typed, high-level programming language created in 1991 by Guido van Rossum. It emphasizes code readability and simplicity—famously described by the motto "There should be one way to do it"—encoded in a philosophy called "The Zen of Python."
Key characteristics: (1) Interpreted — code runs line by line, no compilation step needed. (2) Dynamically typed — variable types are determined at runtime, you do not declare them upfront. (3) Batteries included — standard library includes most utilities you need (file I/O, regex, JSON, HTTP). (4) Extensible — easy to add C/C++ modules for performance-critical code.
Bash excels at chaining existing commands and simple text processing. Python shines when logic is complex: condition trees, rich data structures, error handling, and maintainability. Most infrastructure automation that started in Bash eventually migrates to Python as it scales.
📊 Visual Representation
⌨️ Your First Python Script
# hello.py - Your first script!
print("Hello, DevOps!")
name = "Alice"
print(f"Welcome {name} to Python!")
# Variables work without type declarations
age = 30
print(f"Your age: {age}")
# Lists (arrays in other languages)
servers = ["web01", "web02", "api01"]
for server in servers:
print(f"Server: {server}")