BasicsLesson 1 of 16

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?

⚙️ 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.

🎯
Python 2 vs Python 3

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.

💡
Why Python Beat Bash for Automation

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

Python in the DevOps Stack
Ansible Playbooks
Python Code
Kubernetes Client
Python Automation
Azure SDK
Infrastructure as Code

⌨️ Your First Python Script

python
# 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}")