Command Palette

Search for a command to run...

Hectal
Phase 1Beginner2 of 18 in Python

Values, Variables and Types

Numbers, text and true/false values, the names that hold them, how Python turns one kind of value into another, and how to show results clearly.

Every program works with values: the number 42, the text "Asha", the answer True. This phase teaches the kinds of value Python has (whole numbers, decimals, text, true/false, and "nothing"), how to give a value a name so you can use it again, and what you can do with each kind.

You will also meet the two most common surprises in beginner code: why 0.1 + 0.2 is not exactly 0.3, and why the text "5" is not the number 5. Both come from one idea, that every value has a type, and Python follows the rules of that type exactly.

By the end you can store values, calculate with them, compare them, join them into messages, print them neatly, read what a user types, and write code that other people (and you, next month) can read.

0/11 · 0%
11 topics ~5 h 32 code blocks & diagrams
Start with the first topic
1
1.1

Variables: Names That Point to Values

A variable is a name that points to a value, created with =. The name is a label stuck on the value, not a box that holds it: you can move the label to a different value at any time, and two names can point to the same value.

27 min 1 diagram 2 code practice

2
1.2

Whole Numbers: int

An int is a whole number, positive, negative or zero, with no size limit. Python adds, subtracts and multiplies it exactly, and has special operators for division with a quotient (//), a remainder (%) and powers (**).

26 min 1 diagram 2 code practice

3
1.3

Decimals: float and Why 0.1 + 0.2 Isn't 0.3

A float is a number with a decimal point. Computers store floats in binary, so many everyday decimals such as 0.1 cannot be stored exactly and tiny rounding errors appear. Compare floats with math.isclose, and use decimal or fractions when you need exact answers.

27 min 3 code practice

4
1.4

True, False and None

A bool is either True or False, the answer to a yes-or-no question. None is Python's way of saying "no value here". Every value also has a truthiness: empty and zero values count as false, nearly everything else as true.

25 min 3 code practice

5
1.5

Strings: The Basics

A string (str) is a piece of text: a sequence of characters between quotes. You can measure it with len, pick characters by position, join and repeat strings, and test whether one is inside another. A string can never be changed in place.

24 min 2 code practice

6
1.6

Checking and Converting Types

Every value has a type. type() and isinstance() tell you which, and int(), float(), str() and bool() convert between types when the conversion makes sense. Python never converts text and numbers silently, so "5" + 5 is an error.

24 min 2 code practice

7
1.7

Arithmetic, Precedence and Augmented Assignment

Python follows a fixed order of operations (precedence): powers first, then multiplication and division, then addition and subtraction. Use parentheses to be clear, use += and friends to update a variable, and reach for the math module and built-ins like abs, min and max for more.

26 min 1 diagram 2 code practice

8
1.8

Comparisons and Logic

Comparison operators (==, !=, <, >, <=, >=) ask questions and answer with True or False. and, or and not combine answers. == asks "same value?", is asks "same object?", and and/or stop early and return one of their operands.

28 min 3 code practice

9
1.9

Printing and f-strings

print shows values on the screen and can be tuned with sep and end. An f-string, written f"...{value}...", builds text by putting values into {} slots, and a format spec such as :.2f or :>8 controls how each value looks.

26 min 4 code practice

10
1.10

Reading Input with input()

input(prompt) pauses the program, shows the prompt, waits for the user to type a line and press Enter, and returns what they typed as a string. Convert it with int() or float() before calculating, and check it before you trust it. input() does not work in the browser panels on this site, so the examples here use fixed values.

26 min 3 code practice

11
1.11

Comments, Names and PEP 8

A comment is a note for human readers that Python ignores. Good code is mostly readable names, with comments explaining *why*. PEP 8 is Python's shared style guide (four-space indents, snake_case names, CAPITAL constants), and tools such as Ruff apply it automatically.

25 min 3 code practice

Practise this phase

Hands-on exercises: write the code, run it, and press Check to have it tested automatically.