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