Can we use measurement cookies?

Google Analytics helps us understand public-page journeys, and Google Ads tells us when an advert leads to a trial signup or confirmed purchase. If you accept, measurement cookies connect those visits and conversions. We never send names, email addresses, learner answers or code, and advertising is not personalised.

Your choice is saved in this browser for one year and is not cleared when you log out. Private browsing or clearing browser data can make this question appear again.

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.

Choose a valid name

Use a name such as total_score that explains what is stored. Names can contain letters, digits and underscores, but cannot start with a digit or contain spaces. score2 is valid; 2score is not. A name cannot be a keyword such as for, and uppercase and lowercase letters are different.

Specification link

OCR reference

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

  • 2.2.1
  • 2.2.2

Continue with the complete course

Start a free 7-day trial to explore lessons, revision and practice with progress saved to the learner’s account.

Start the free 7-day trial