7.19 Hands-on Exercises & Mini Projects
CPU Usage Calculator Build a function that takes total CPU time used and elapsed time, and returns the percentage utilization using …
CPU Usage Calculator Build a function that takes total CPU time used and elapsed time, and returns the percentage utilization using …
Conceptual Questions What is the difference between == and is? What is short-circuit evaluation, and why does it matter? Explain operator …
Readable Expressions Favor clarity over compactness — an expression that takes an extra half-second to parse mentally, multiplied across …
Operators are the backbone of every monitoring/validation script — these five patterns cover most of what shows up in practice. CPU/Disk …
Efficient Expressions Prefer x in a_set over x in a_list for repeated membership checks on large collections (see 7.7 Membership Operators) …
Using is Instead of == What Goes Wrong? is compares identity, not value — it can appear to work for small integers or short strings, due to …
Several operators behave completely differently depending on the operand type — + means numeric addition for numbers, but concatenation for …
Syntax Python allows writing a < b < c directly, unlike languages where you’d need (a < b) and (b < c) explicitly. …
Syntax What Is It? A one-line if/else that produces a value rather than executing a statement block: value_if_true if condition else …
What Is It? Python treats every value as either “truthy” or “falsy” in a boolean context (if x:, while x:, bool(x)) …
Operator Precedence What Is It? The order in which operators are applied when an expression mixes several of them, without any parentheses …
This section covers is/is not specifically as comparison operators. The underlying concept — a variable being a reference to an object, not …
in What Is It? Tests whether a value exists within a collection (list, string, dict keys, and so on), returning a bool. >>> 3 in …
What Are They? Operators that work on the individual bits of an integer’s binary representation, rather than its decimal value. Why …
flowchart TD subgraph AND["and — True only if BOTH are truthy"] direction LR A1["True and True → True"] A2["True and False → False"] …
What Are They? Operators that compare two values and always return a bool. Why Are They Used? The foundation of every conditional (if, …
= Plain assignment binds a name to a value — already covered in 4.8 Variables and 6.4 Assignment Operations. >>> x = 5 >>> …
The standard mathematical operators, all usable on int and float (and some on other types, see 7.13 Operators with Different Data Types). …
flowchart TD O["Operators"] O --> AR["Arithmetic\n+ - * / // % **"] O --> AS["Assignment\n= += -= ..."] O --> CO["Comparison\n== != < > <= >="] …
Arithmetic Operators A=10 B=3 echo $((A + B)) # 13 echo $((A - B)) # 7 echo $((A * B)) # 30 echo $((A / B)) # 3 — integer division, no …
Q1 What is Helm and why is it used in Kubernetes? Intermediate Helm is the package manager for Kubernetes. It lets you define, install, and …