Can we use analytics cookies?

Google Analytics measures basic public-page use without setting analytics cookies. If you accept, cookies help us understand repeat visits and journeys. We never send names, email addresses, learner answers or code.

Read the cookie details

Complete public chapter · no account needed

Output, variables and data

How Python displays information, stores values and updates a program’s state. This is the same chapter students can use in the Course Guide after signing in.

Fast reminder

Quick facts

String
Text stored between quotation marks.
Variable
A named place in memory that stores a value.
Assignment
Giving a value to a variable using =.
Sequence
Instructions carried out in order, usually from top to bottom.

Section 1

Displaying information

Use print() and predict the exact output of a sequence.

The print function

print() sends information to the console. Text is a string and needs matching quotation marks. Each call normally ends with a new line. Python is case-sensitive, so print and Print are different names.

Labels and values

A comma lets one print() call display several values with spaces between them. Keep calculations outside quotation marks if Python should evaluate them. print("Total:", 6 + 4) displays Total: 10; print("6 + 4") displays the text 6 + 4.

Section 2

Variables and assignment

Store values with meaningful names and update them as a program runs.

Names and values

An assignment such as score = 10 stores the integer 10 using the name score. The equals sign means assign, not “is mathematically equal to”. Choose names that explain the purpose of the value.

Changing state

A later assignment replaces the current value. In score = score + 1, Python reads the current value on the right, adds one and stores the new value back in score.

Specification link

OCR reference

This chapter supports OCR GCSE Computer Science J277, component J277/02.

  • 2.2.1
  • 2.2.2

Continue with saved learning

The trial adds lessons, revision and practice, with progress saved to the learner’s account. This public chapter does not ask questions or save learning progress.

Start the free trial