teluzia.Cloud Engineer · Day 22
CHAPTER 04 · PYTHON FUNDAMENTALS

Syntax, variables, data types and operators

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

Use Python as a precise language for expressing values and calculations. You will run a small script, inspect types and fix a deliberate mixed-type expression. The exercises use synthetic values and standard Python only, so you can focus on syntax and evaluation rather than external packages. Python uses indentation to group suites of statements and requires consistent structure. Source files are executed by the interpreter, while the interactive prompt evaluates entries incrementally. Comments begin with # outside strings. A syntax error prevents parsing; a runtime error occurs after successfully parsed code begins executing. Assignment binds a name to an object. Common built-in types include int, float, str, bool and NoneType. Names can later bind different objects, but operations depend on current types. type reveals an object’s type; explicit conversion such as int("12") parses suitable textual input rather than making every string numeric.

Think of it this way

A variable is a name tag attached to an object; an operator describes how objects interact.

TOPIC 01 / 03Step by step

Syntax and execution

Python uses indentation to group suites of statements and requires consistent structure. Source files are executed by the interpreter, while the interactive prompt evaluates entries incrementally. Comments begin with # outside strings. A syntax error prevents parsing; a runtime error occurs after successfully parsed code begins executing. python3 -m py_compile values.py checks whether a source file parses; python3 values.py then executes its actual statements and can reveal runtime errors. Distinguishing parsing from runtime behavior helps locate failures quickly and explains why a valid-looking file may compile successfully yet fail while evaluating a particular expression during execution. Mixing tabs and spaces or omitting a colon can break block structure; use consistent four-space indentation and read the reported location before changing unrelated statements in the program.

WORKED EXAMPLE
python3 -m py_compile values.py checks whether a source file parses; python3 values.py then executes its actual statements and can reveal runtime errors.
Why this matters

Distinguishing parsing from runtime behavior helps locate failures quickly and explains why a valid-looking file may compile successfully yet fail while evaluating a particular expression during execution.

A common trap

Mixing tabs and spaces or omitting a colon can break block structure; use consistent four-space indentation and read the reported location before changing unrelated statements in the program.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Syntax and execution

Python uses indentation to group suites of statements and requires consistent structure. Source files are executed by the interpreter, while the interactive prompt evaluates entries incrementally. Comments begin with # outside strings. A syntax error prevents parsing; a runtime error occurs after successfully parsed code begins executing. python3 -m py_compile values.py checks whether a source file parses; python3 values.py then executes its actual statements and can reveal runtime errors. Distinguishing parsing from runtime behavior helps locate failures quickly and explains why a valid-looking file may compile successfully yet fail while evaluating a particular expression during execution. Mixing tabs and spaces or omitting a colon can break block structure; use consistent four-space indentation and read the reported location before changing unrelated statements in the program.

WORKED EXAMPLE
python3 -m py_compile values.py checks whether a source file parses; python3 values.py then executes its actual statements and can reveal runtime errors.

Why this matters

Distinguishing parsing from runtime behavior helps locate failures quickly and explains why a valid-looking file may compile successfully yet fail while evaluating a particular expression during execution.

A common trap

Mixing tabs and spaces or omitting a colon can break block structure; use consistent four-space indentation and read the reported location before changing unrelated statements in the program.

Variables and data types

Assignment binds a name to an object. Common built-in types include int, float, str, bool and NoneType. Names can later bind different objects, but operations depend on current types. type reveals an object’s type; explicit conversion such as int("12") parses suitable textual input rather than making every string numeric. price=12; label="12"; print(type(price).__name__, type(label).__name__) prints int str even though both display similar characters in some output contexts. Knowing types prevents accidental string concatenation, numeric conversion errors and boolean confusion when reading inputs from files, forms or environment variables that often arrive as text before validation occurs. Assuming input text is already numeric causes incompatible operations; validate and convert deliberately, and recognize that int("twelve") raises an error rather than inventing a numeric value.

WORKED EXAMPLE
price=12; label="12"; print(type(price).__name__, type(label).__name__) prints int str even though both display similar characters in some output contexts.

Why this matters

Knowing types prevents accidental string concatenation, numeric conversion errors and boolean confusion when reading inputs from files, forms or environment variables that often arrive as text before validation occurs.

A common trap

Assuming input text is already numeric causes incompatible operations; validate and convert deliberately, and recognize that int("twelve") raises an error rather than inventing a numeric value.

Operators and comparison

Arithmetic operators compute values, comparison operators produce booleans, and logical operators combine truth conditions. / performs true division, // floor division and % remainder. == compares equality; = assigns a name. Precedence determines grouping, so parentheses can make intent explicit. Floating-point values approximate many decimal fractions. print(7/2,7//2,7%2,7==2) produces 3.5, 3, 1 and False; a negative operand makes floor division different from simply truncating toward zero. Explicit operator choice produces correct units and conditions and avoids silent mistakes in counters, thresholds and capacity calculations that otherwise look plausible when printed in an automation report or lab note. Using = where a comparison is needed is invalid in a normal condition; also avoid exact equality assumptions for computed floating-point decimals unless the representation and tolerance are understood.

WORKED EXAMPLE
print(7/2,7//2,7%2,7==2) produces 3.5, 3, 1 and False; a negative operand makes floor division different from simply truncating toward zero.

Why this matters

Explicit operator choice produces correct units and conditions and avoids silent mistakes in counters, thresholds and capacity calculations that otherwise look plausible when printed in an automation report or lab note.

A common trap

Using = where a comparison is needed is invalid in a normal condition; also avoid exact equality assumptions for computed floating-point decimals unless the representation and tolerance are understood.

KEEP THESE WITH YOU

Today’s takeaways

Separate parsing from execution.

Inspect input types.

Choose operators and grouping deliberately.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed