Booleans, and a Glimpse of Collections

A Boolean holds one of exactly two values: true or false. Booleans are how programs make decisions, is the user signed in? is the answer correct? Comparisons produce them.

EXAMPLE
loading editor…
YOUR TURN
Your turn → Write three comparisons of your own: one that prints True, one that prints False, and one that checks whether two pieces of text are equal.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

Single values are only the beginning. Programs mostly work with collections: Python lists / JavaScript arrays hold ordered sequences; Python dictionaries / JavaScript objects hold labeled fields. Here's a preview, Level II lives here.

Collections preview

PYTHON

freedom_singers = ["Rutha", "Bernice", "Cordell"]
elder = {"name": "Fannie Lou Hamer", "born": 1917}

JAVASCRIPT

let freedomSingers = ["Rutha", "Bernice", "Cordell"];
let elder = { name: "Fannie Lou Hamer", born: 1917 }; 
Compare → Nearly identical syntax for sequences. For labeled data, Python quotes its keys; JavaScript usually doesn't. Full mastery comes in Module 8: today you just need to recognize them on sight.
EXAMPLE
loading editor…
YOUR TURN
Your turn → Positions start at 0, not 1. Print the third singer using her position.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

◈ Graded Challenge

Create four variables that demonstrate four different types: a_number holding 1957, a_text holding the text 1957, a_decimal holding 3.5, and a_flag holding true.

Name it exactly: a_number, a_text, a_decimal, a_flag

4 visible + 1 hidden
loading editor…

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Practice Test →
← Back