What's covered
Key facts
Arithmetic Operators
In Python the division operator is the forward slash /. 10 / 4 returns 2.5.
Common Python Errors
IndentationError means the indentation (spaces or tabs at the start of a line) is not consistent with the surrounding block.
Comparison Operators
Every comparison in Python returns a Boolean: True or False.
Data Types: Integer, Float, String, Boolean
Python's bool type stores one of two values: True or False.
Functions (Subroutines)
def add(a, b): return a + b, add(2, 3) returns 5.
Input and Output
input() does not return an integer by default: it returns a string; conversion is the programmer's job.
Lists and Indexing
xs.append(5) adds 5 to the end of the list xs.
Parameters and Return Values
def double(n): return n * 2, double(double(3)) is double(6) = 12.
String Operations
'hello' + ' world' gives 'hello world' because the second string starts with a space character.
Variables and Assignment
After x = 7, the value of x is the integer 7, not zero, not the letter "x", not undefined.
Practice questions with answers
A taste of the 92 questions in this topic, answers marked. Sign up to practise the full set with spaced repetition.
What is 10 % 3 in Python?
- ✓One (the remainder)
- •Ten (the original value)
- •Three (the quotient)
- •Zero (no remainder)
What is a syntax error?
- ✓Code breaks language rules
- •Program crashes only with certain inputs
- •Program runs but gives wrong output
- •Variable holds an unexpected data type
What does 5 > 3 evaluate to?
- •False
- •Five
- •Three
- ✓True
Name two common Python data types.
- ✓Integer and string
- •Loop and function
- •Syntax and logic
- •Variable and constant
Why use functions in code?
- •To increase the chance of a syntax error
- •To make the program run more slowly
- •To remove the need for any variables
- ✓To reuse code and reduce repetition
What does name = input('your name:') do in Python?
- •Counts how many letters are in 'name?'
- •Prints the word 'name?' and stops
- •Sets a variable to the string 'name?'
- ✓Shows prompt and reads user input
Three minutes a day. Knowledge that sticks.
Practise all 92 Programming in Python questions with spaced repetition, so what you revise today is still there in the exam. Free to use, no card needed.