- The Routing Intent by Leonardo Furtado
- Posts
- Chapter 15: Decision-Making with Comparators and Conditionals
Chapter 15: Decision-Making with Comparators and Conditionals
From == to if/elif/else, this guide shows network engineers how to teach Python to think clearly, compare accurately, and act intelligently.

1. Letting Python Think for You
In every automation task, especially those involving computer networks, making decisions is at the core of the process. Imagine you're monitoring hundreds of devices in a network, and your automation script needs to know whether a router is healthy, if an interface is down, or whether a link’s latency has exceeded acceptable thresholds. How does your code “decide” what to do next?
That’s where comparators and conditionals come in.
They give your Python code the ability to evaluate, choose, and react. These are the tools that enable scripts to branch off and make decisions dynamically, such as “If this interface is down, raise an alert” or “If packet loss exceeds 2%, log an incident.”
This article introduces you to:
Python comparators (also known as relational operators), which help you compare two values or states, like is X greater than Y? or does A equal B?
Conditionals, such as
if
,else
, andelif
, which lets your code take action based on those comparisons.Logical operators, like
and
,or
, andnot
, which allows combining multiple conditions for more complex logic.
These are core programming concepts, and when paired with your networking expertise, they become the foundation of powerful decision-making automation logic. Whether you’re building a topology validator, a telemetry parser, or a custom monitoring agent, understanding Python’s comparison and conditional structures is non-negotiable.
Why This Matters in Networking
In real-world network engineering, you are constantly evaluating things like:
Interface utilization: Is it over 80%? If so, alert.
BGP neighbor state: Is it “Established”? If not, log and notify.
Device inventory match: Does the current OS version match the golden config?
Reachability: Is the device responding to ICMP or SNMP? If not, retry. If still down, escalate.
You’ll see all these use cases, and more, brought to life in this article.
What You’ll Learn
By the end of this post, you will:
✅ Understand all six Python comparators and how to use them with numbers, strings, and variables
✅ Write clear, efficient conditional logic using if
, elif
, and else
✅ Combine multiple comparisons into smart decisions using and
, or
, and not
✅ Apply all of this to realistic network automation problems, with example code and step-by-step explanations
✅ Run the exercises and experiment in your own IDE to develop deep familiarity
So open your Python editor or Jupyter Notebook, because you’re not just going to read about comparators: you’re going to test them, break them, and understand how they become part of your network engineer’s toolkit.
Let’s dive in.