All guides

PUBLIC LEARNING GUIDE

Read data before changing code

Understand values, conditions, loops and the boundary between JSON text and Python data.

Names hold values with types

A variable is a name for a value. A string such as "3" and the number 3 look similar when printed but behave differently. Before comparing or calculating, inspect the type expected by the operation. Avoid converting values merely to make an error disappear.

A dictionary stores values under keys; a list keeps an ordered sequence. In a customer record, email is a key. In a list of customers, each element is a record. These are different layers and need different access steps.

customer = {"name": "Sam", "email": "sam@example.test"}
print(customer["email"])

Conditions choose; loops repeat

An if block runs only when its condition is true. A for loop visits each item in a sequence. Indentation defines which statements belong to a block. The example prints only the available addresses, once per record.

Try an empty customers list, a record with an empty email and two valid records. Predict how many lines will be printed before running it. This example assumes every record contains the email key; an absent key needs a separate validation step.

customers = [{"email": "sam@example.test"}, {"email": ""}]
for customer in customers:
    if customer["email"]:
        print(customer["email"])

JSON is text with a strict format

JSON is a data exchange format, not Python code. Object keys use double quotes. Its boolean values are true and false and its empty value is null. Python uses True, False and None. Valid JSON also excludes comments and trailing commas.

In a normal Python environment, json.loads converts JSON text to Python values. Parsing only checks the format: you still need to validate the required keys and types. The local Python example below uses the standard library; imports are not supported by Kyrelio’s bounded lesson runner.

import json
text = '{"email": "sam@example.test", "active": true}'
record = json.loads(text)
print(record["active"])

Practice a small change

Change the loop to print each valid customer’s name instead of their address. Decide what must be true before reading that field. Then introduce one wrong key deliberately and identify the first failing operation.

Keep a note of the input, expected output and the reason for your fix. A useful explanation names the mistaken assumption rather than saying only that the new code works.

Automation Fundamentals 2.0: quick reference

customers = [{"email": "sam@example.test"}]
for customer in customers:
    if customer["email"]:
        print(customer["email"])
String
Text, usually written in quotes.
Dictionary
Key/value mapping; record["email"] reads a required key.
List
Ordered sequence; a for loop can visit each item.
if / else
Select a branch. Use four spaces for block indentation in Kyrelio.
JSON → Python
true → True; false → False; null → None. Parse text before reading fields.
Runner limits
Kyrelio supports a bounded Python subset, not arbitrary packages or operating-system access.
Explore the related course

Ask a question or report a confusing explanation

Read data before changing code | Kyrelio