Session XP: 0
Spec 1.2.3, 6.3.3, 6.5Paper 1 and Paper 2

Operators and String Handling

Arithmetic, relational and logical operators, and string handling (length, position, substrings, case) in Python.

—
Best score
—
Last attempt
Best attempt progress
0
XP earned
Watch first
Craig 'n' Dave · Edexcel 1CP2The common arithmetic and comparison operators (4:55)
Craig 'n' Dave · Edexcel 1CP2The common Boolean operators (3:32)
Craig 'n' Dave · Edexcel 1CP2The use of basic string manipulation (16:12)
Craig 'n' Dave · Edexcel 1CP2Formatting and customising string output (7:09)
Craig 'n' Dave · Edexcel 1CP2Using arithmetic, comparison and logic operators in programs (8:40)
Reference & Examples

Arithmetic operators in Python — fill in the table

OperatorMeaning / example
+ - * /
% (modulus)
// (integer division)
** (exponentiation)
Order of operations
Exam wording

Relational (comparison) operators — fill in the table

OperatorMeaning
== and !=
< and >
<= and >=
Result
Example
Common slip

Logical operators — fill in the table

OperatorMeaning / example
and
or
not
Combined example
Truth

Strings in Python (spec 6.3.3) — fill in the table

OperationMeaning / example
len(s)
s[i]
s[a:b]
s.upper() and s.lower()
s.find(x)
Concatenation (+)
String handling in Python
name = "Ander"
print(len(name))          # 5
print(name[0:3])          # And
print(name.upper())       # ANDER
print(name[0])            # A
print(name.find("d"))     # 2

if name[0].upper() == "A":
    print("Name starts with A")

greeting = "Hello, " + name + "!"
print(greeting)           # Hello, Ander!
Modulus and integer division
print(10 % 3)    # 1
print(8 % 2)     # 0, so 8 is even
print(17 // 5)   # 3
print(17 % 5)    # 2, because 17 = 3 * 5 + 2
print(2 ** 3)    # 8

num = int(input("Enter a number: "))
if num % 2 == 0:
    print("Even")
else:
    print("Odd")
Exam practice — 7 questions · 13 marks · 1CP2 Paper 2 style
⚡ In the real Paper 2 you type and run Python on screen. Here, type your Python answer and the AI marks it against the mark points. Check the Programming Language Subset (PLS) you are given in the exam for the exact commands.
1 markModulusPaper 1 · spec 1.2.3

What is the result of 17 % 5 in Python?

A 3
B 2
C 5
D 0
1 markString lengthPaper 2 · spec 6.3.3

What does len("Computing") return?

A 8
B 9
C 10
D 7
3 marksSubstrings and casePaper 2 · spec 6.3.3

A variable word holds "Python". Write Python to (a) print the first 3 characters, (b) print the word in capitals, (c) print the last character. (3 marks)

Hint: (a) Use a slice [start:stop]. (b) Use .upper(). (c) The last index is len(word) - 1, or -1.
+30 XP
4 marksOperators in conditionsPaper 2 · spec 6.5

Write a Python program that asks the user for a whole number, then prints "FizzBuzz" if it is divisible by both 3 and 5, "Fizz" if divisible by 3 only, "Buzz" if divisible by 5 only, and otherwise prints the number. (4 marks)

Hint: Test for both first. Use % to test divisibility.
+40 XP
1 markLogical operatorPaper 1 · spec 1.2.3

What is the result of (5 > 3) and (10 < 8)?

A True
B False
C An error
D 0
1 markRelational operatorPaper 1 · spec 1.2.3

Which Python operator tests that two values are NOT equal?

A <>
B !=
C =!
D ==
2 marksPosition and substringsPaper 2 · spec 6.3.3

State what is printed by this code. (2 marks)

word = "computer"
print(word.find("e"))
print(word[2:5])
Hint: Count from 0. A slice stops before its last index.
+20 XP
Quick recall flashcards

Module complete! 🎉

Score loading...

⚡ +10 XP