Logical operators (Edexcel GCSE Computer Science): Revision Notes
Logical operators
What are logical operators?
Logical operators are special symbols that help programmers make decisions by combining different conditions together. Think of them like the words "and", "or", and "not" that we use in everyday speech to connect ideas. In programming, these operators work with Boolean values (true or false) to help your programme decide what to do next.
When you use logical operators with relational operators (like >, <, ==), you can create more complex conditions that make your programmes much smarter and more flexible.
The three main logical operators

Let's look at each logical operator and understand how they work:
The 'and' operator
The and operator is like saying "both things must be true". It only returns True when both sides of the condition are true. If even one side is false, the whole thing becomes false.
Example: Age and License Check
(age >= 18) and (hasLicense == True)
- This only returns True if the person is 18 or older AND they have a license
- If they're 20 but don't have a license, it returns
False - If they have a license but are only 16, it returns
False
The 'or' operator
The or operator is more flexible - it means "at least one thing must be true". It returns True when either side (or both sides) of the condition is true. It only returns False when both sides are false.
Example: Weekend Day Check
(day == "Saturday") or (day == "Sunday")
- This returns True if it's either Saturday OR Sunday (or somehow both!)
- It only returns
Falseif it's a weekday
The 'not' operator
The not operator is like flipping a switch - it inverts (reverses) the result. If something is True, not makes it False. If something is False, not makes it True.
Example: Game Status Check
not (gameOver == True)
- If the game is over (gameOver is
True), this returnsFalse - If the game is still going (gameOver is
False), this returns True
Understanding Boolean data types
When you use logical operators, you're working with Boolean data types. This means your conditions can only have two possible values: True or False.
How Boolean Evaluation Works:
Here's how it works step by step:
- Each condition on either side of the logical operator gets evaluated first
- The computer figures out if each part is
TrueorFalse - Then the logical operator combines these results
- Finally, you get one single
TrueorFalseanswer
Important note: The and and or operators need something on both sides to compare. The not operator only needs one thing to flip around.
Using logical operators in your programmes
Logical operators are super useful when working with selection statements (like if...elif...else) and repetition loops (like while). They help you create more sophisticated conditions that can handle multiple scenarios at once.
Practical Example: All Three Operators in Action
roll = 7
guess = -2
total = 0
count = 4
statElectricity = False
statWater = True
# Using 'or' operator
if ((roll > 6) or (guess < 1)):
print("Invalid")
# Using 'and' operator
if ((statWater == True) and (statElectricity == False)):
print("Safe to enter")
# Using 'not' operator
statElectricity = True
if ((statWater) and (not statElectricity)):
print("Safe to enter")
else:
print("Stay out")
# Using 'not' in a while loop
while (not (total >= 4)):
total = total + 1
print(total)
Exam tips and common mistakes
Remember these key points:
- and needs ALL conditions to be true
- or needs AT LEAST ONE condition to be true
- not flips the result (true becomes false, false becomes true)
- Always use brackets to make your conditions clear: ((age >= 18) and (hasTicket == True))
- Test your logical conditions with different values to make sure they work correctly
Common pitfall: Don't confuse and with or! Many students mix these up in exam questions. Remember: and is stricter (needs everything), or is more flexible (needs anything).
Remember!
Key Points to Remember:
- Logical operators combine Boolean conditions to make complex decisions in your programmes
- and operator requires both sides to be true - it's like saying "this AND that must both happen"
- or operator requires at least one side to be true - it's like saying "this OR that (or both) must happen"
- not operator flips the result - it turns true into false and false into true
- These operators are essential for creating smart selection and repetition structures in your code