# 13.3 Values, types and variables (/building-ai-workers/programming-fundamentals/values-types-variables)

---
type: Document
title: "13.3 Values, types and variables"
description: "How to make a variable in TypeScript and Python, what kinds of value it can hold, how a list and an array compare, why text from a file is not a number, and why money is kept in whole cents."
status: stable
order: 313.03
ksor:
  owner: team:panaversity
  audience: [ public ]
  approval:
    by: process:panaversity
    at: 2026-11-10T15:33:14Z
chapter: "13"
part: III
expert_status: builder-only
concepts: [ "13.3" ]
last_verified: 2026-10-30
generated:
  at: 2026-11-10T15:33:14Z
  by: process:panaversity
trust_tier: unverified
build_id: sha256:46fd53c5d7ab1c14f6347908d45c9fdaecda4d914439923ee878bdcecd57803e
dirty: true
ksor_version: 0.0.60
---

**In everyday life.** The characters 4-8-2-5-0-0 can be an amount, a postal code or a part number. You add amounts. You never add postal codes. What you may do depends on what kind of thing they are, not on how they look.

**What you will learn.** How to make a variable, what kinds of value it can hold, and how to spot text that only looks like a number.

**Why it matters.** A number read from a file is only text until the code turns it into a number, so check that the code does this before it adds anything.

A value's type decides what you can do with it.

### How do I make a variable?

With a name, an `=` and a value. Think of a label on a folder: the name is the label, and the value is what the folder holds. The `=` means "store this value under this name".

In TypeScript, the first word says how the label is written. `const` is ink: the name cannot be given a new value. `let` is pencil: it can. Python has neither word. The name and `=` are enough, and every label is in pencil.

Two things help you read the code below. Text after `//` in TypeScript, or `#` in Python, is a **comment**, a note for people that the program skips. And a `console.log` or `print` with two values prints both on one line. Predict what each one prints.

```ts tab="TypeScript" tab-group="language"
const terms = "Net 30";   // const, ink: cannot be given a new value
let total = 0;            // let, pencil: can be given a new value
total = total + 482500;   // read total, add to it, store it again
console.log(terms, total);
```

```python tab="Python" tab-group="language"
terms = "Net 30"         # just the name and =
total = 0
total = total + 482500   # read total, add to it, store it again
print(terms, total)
```

Both print:

```text
Net 30 482500
```

`total` started at 0. The third line read it, added 482500, and stored the result under the same name.

### What kinds of value are there?

Five do most of the work.

| Kind of value | TypeScript | Python | Brightline example |
| --- | --- | --- | --- |
| Text | `string` | `str` | `"INV-8301"`, `"Net 30"` |
| Whole number | `number` | `int` | `482500` cents |
| Decimal number | `number` | `float` | Never used for money |
| True or false | `boolean` | `bool` | Is the invoice open? |
| Nothing | `null` or `undefined` | `None` | A record with no due date at all |

These are the words a **type label** uses, such as `cents: number` or `cents: int`. An agent follows the labels you give it, so choosing them is part of the first 10 percent.

### Is a Python list the same as a TypeScript array?

Yes, for reading code. They are the same idea under two names, and this book says "list" for both.

| | TypeScript array | Python list |
| --- | --- | --- |
| How many items | `ids.length` | `len(ids)` |
| Add one at the end | `ids.push("V003")` | `ids.append("V003")` |
| Its type label | `string[]` | `list[str]` |

`const` fixes the name, not what is inside the list. The ink label stays on its folder, and you can still add a page to the folder. So `push` is allowed. Predict what each one prints.

```ts tab="TypeScript" tab-group="language"
const ids = ["V001", "V002"];
ids.push("V003");
console.log(ids.length, ids[2]);
```

```python tab="Python" tab-group="language"
ids = ["V001", "V002"]
ids.append("V003")
print(len(ids), ids[2])
```

Both print:

```text
3 V003
```

### Why is an amount from a file still text?

Everything a program reads from a CSV file arrives as text, including the amounts. `"482500"` is six characters, not a number, until your code converts it.

`Number(...)` in TypeScript and `int(...)` in Python convert text to a number. Predict each line, and what happens on the last one.

```ts tab="TypeScript" tab-group="language"
const fromFile = "482500";                       // text, as a file gives it
const other = "61875";                           // text
console.log(fromFile + other);                   // text + text
console.log(Number(fromFile) + Number(other));   // number + number
console.log(0 + fromFile);                       // number + text
```

```python tab="Python" tab-group="language"
from_file = "482500"                       # text, as a file gives it
other = "61875"                            # text
print(from_file + other)                   # text + text
print(int(from_file) + int(other))         # number + number
print(0 + from_file)                       # number + text
```

```text tab="TypeScript" tab-group="language"
48250061875
544375
0482500
```

```text tab="Python" tab-group="language"
48250061875
544375
Traceback (most recent call last):
  ...
TypeError: unsupported operand type(s) for +: 'int' and 'str'
```

What `+` does depends on the kind of value, as with the amount and the postal code. On two strings it joins them, like two postal codes written side by side. On two numbers it adds. On a number and a string, TypeScript turns the 0 into text and joins. Python stops instead.

Text with a comma in it cannot be converted. `Number("4,825.00")` gives `NaN` in TypeScript, which means "not a number", and `int("4,825.00")` stops with a `ValueError` in Python.

The TypeScript behavior is the dangerous one, because the program keeps running with a wrong value.

### Why whole cents?

Because decimal numbers can be very slightly off. A computer does not store most of them exactly. Predict what each one prints.

```ts tab="TypeScript" tab-group="language"
console.log(1.10 + 2.20, 110 + 220);
```

```python tab="Python" tab-group="language"
print(1.10 + 2.20, 110 + 220)
```

Both print:

```text
3.3000000000000003 330
```

The whole numbers came out exact. So this book keeps every amount in whole cents, $48.25 as `4825`, and turns cents into dollars only when it prints them. Never let an agent keep money in an ordinary decimal number.

### Try it

The file in `13-3` is the text-or-number program. Run it and investigate, as in [13.1](you-read-the-agent-writes.md#try-it).

**Modify.** Real exports often write an amount as `"4,825.00"`. Send: "Please change `482500` to `4,825.00` on the first line of the file. Don't run it yet." Write down what each line will print. Then ask the agent to run it.

**Make.** Send: "Please make a new file in 13-3 called mine that keeps two invoice amounts as whole cents in variables, adds them, and prints the total. Don't run it yet." Check the total yourself, then ask the agent to run it.

**What you should see.** TypeScript keeps going: the joined text, then `NaN` where it converts the amount. Python stops at its second print, with a `ValueError`, because `"4,825.00"` is not a whole number.

**The operating rule:** convert text from a file as soon as the code reads it, keep money in whole cents, and label the types so a checker can check them.

![Figure 13.3. The same characters as text and as numbers. As text, "482500" plus "61875" joins into "48250061875". As numbers, 482500 plus 61875 is 544375 cents, which is $5,443.75. Converting checked text with Number() first gives 544375.](img/text-or-number.png)

*Figure 13.3. Text or number. The characters are the same. The type decides what plus means.*

**Next.** [13.4](decisions-and-repetition.md) shows how a program decides what to do with each invoice.
