ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Variables/Creating variables
J277 · 2.2.1

Unit 2 · Lesson 1

Creating variables

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Create variables using meaningful names and the assignment operator.

A variable is a labelled place in memory. The line score = 0 creates a variable called score and assigns the integer 0 to it. Choose names that explain the value; player_name is clearer than x. A constant stores a value that should stay fixed.

Variable

A named location in memory that stores a value which can change.

Constant

A named value that should not change while a program runs.

Assignment

Storing a value in a variable using the = operator.

Identifier

The exact name given to a variable, constant or subroutine.

Keep these in mind

  • Use = to assign a value.
  • The variable name goes on the left and its value goes on the right.
  • Names cannot contain spaces and should describe their purpose.
  • ERL declares a constant with const; Python uses an UPPERCASE name by convention.

Learning objective

Create variables using meaningful names and the assignment operator.

Exam tip

If asked to identify a variable, copy its exact identifier from the code. Do not give the value stored inside it.

Common mistake

Use one equals sign (=) for assignment. Two equals signs (==) compare values and do not store anything.

PreviousNext