Skip to main content

Command Palette

Search for a command to run...

Day 94: Variables, Loops, and Conditionals in Python

Mastering Variables, Loops, and Conditionals in Python for DevOps Success

Published
β€’1 min read
Day 94:  Variables, Loops, and Conditionals in Python

Today, I dived into the core building blocks of Python scripting β€” variables, loops, and conditionals β€” which are essential to build logic and control flows in automation scripts.


πŸ“Œ Variables

Variables let you store and reuse values in your scripts.

env = "production"
server_count = 5
print(f"Deploying to {env} with {server_count} servers")

πŸ“ Useful in DevOps to hold environment names, IPs, credentials (via secrets), and configuration values.


πŸ” Loops

Loops let you repeat tasks, such as configuring multiple servers or checking service statuses.

servers = ["web01", "web02", "db01"]
for s in servers:
    print(f"Configuring {s}")

πŸ“ Great for batch operations like container cleanup, log rotation, or restarting services.


⚑ Conditionals

Conditionals allow your script to decide what to do based on certain conditions.

status = "running"
if status == "running":
    print("All systems operational.")
else:
    print("Something is wrong!")

πŸ“ Helps in automation checks, error handling, and branching workflows.


πŸ’‘ Key Takeaways

βœ… Variables make your scripts dynamic and reusable
βœ… Loops help scale actions across multiple servers or resources
βœ… Conditionals provide decision-making logic to your scripts

DevOps overview as a beginner

Part 1 of 50

Sharing my journey of learning DevOps as a beginner β€” covering essential tools, cloud setup, CI/CD, Docker, monitoring, and more, step by step with practical examples.