Expressions and Statements

An expression is a piece of code that produces a value: 2 + 3 produces 5. "Ama" produces the text Ama.

A statement is a complete instruction: print this, store that. Statements often contain expressions, print(2 + 3) is a statement holding the expression 2 + 3.

EXAMPLE
loading editor…
YOUR TURN
Your turn → Write one more line that calculates the number of days in 52 weeks (52 * 7).
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.

✦ Key distinction

print("7 + 3") with quotes prints the characters 7 + 3. print(7 + 3) without quotes evaluates the expression first and prints 10. Quotes mean "treat this as text." No quotes mean "work this out."

EXAMPLE
loading editor…
YOUR TURN
Your turn → Add two lines of your own: one that prints the text 52 * 7 exactly as written, and one that prints the number of days in 52 weeks, worked out by the computer.
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.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Two Languages, One Way of Thinking →
← Back