SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
Edexcel 1CP2 · Topic 6 · 6.2b

Logical Operators &
String Operations

and · or · not · Concatenation · len() · upper() · lower() · find()

CSZoneEdexcel GCSE Computer Science 1CP2
Logical Operators

Combining Conditions

age = 17
has_id = True

if age >= 18 and has_id: # both must be True
print("Entry allowed")

if age < 12 or age > 65: # either can be True
print("Reduced fare")

if not has_id: # reverses True/False
print("No ID — denied")
and: True only if BOTH conditions are True
or: True if AT LEAST ONE condition is True
not: flips True to False and False to True
String Operations

Working with Text

name = "Alice"
print(len(name)) # 5
print(name.upper()) # ALICE
print(name.lower()) # alice
print(name[0]) # A (first character)
print(name[-1]) # e (last character)
print(name[1:3]) # li (slicing)
Strings are zero-indexed: first character is index 0
Slicing: s[start:stop] — start inclusive, stop exclusive
Strings are immutable — you cannot change a single character; you must create a new string
More String Methods

Useful Built-in Functions

sentence = "Hello World"
print(sentence.find("World")) # 6 (index)
print(sentence.replace("World","Python")) # Hello Python
print(sentence.split(" ")) # ['Hello', 'World']
print(" hello ".strip()) # "hello"

# Concatenation
first = "Hello"
full = first + " " + "World" # Hello World
+ concatenates strings; * repeats: "ha"*3"hahaha"
in checks membership: "lo" in "Hello" → True
Exam Practice

Have a go at this question

Edexcel-style question
What is the output of this code?

word = "Computer"
print(word[3])
print(len(word))
print(word[0:4].upper())
3 marks
p (index 3) [1]. 8 [1]. COMP (characters 0,1,2,3 → "Comp" → upper → "COMP") [1].
Key Takeaways

What to Remember

and: both True; or: at least one True; not: reverses the boolean
Strings are zero-indexed; slicing [start:stop] — stop is exclusive
Key methods: len(), upper(), lower(), find(), replace(), split(), strip()
Strings are immutable — any method returns a new string, the original is unchanged