Skip main navigation

New offer! Get 30% off one whole year of Unlimited learning. Subscribe for just £249.99 £174.99. New subscribers only. T&Cs apply

Find out more

Logical operators

Learn algorithms, logic, and Python basics. Create simple programs, grasp computer science fundamentals, and see its impact across various fields.

This step we will revisit some basic logical operators.

The AND Operator

Input (A) Input (B) AND Outrput
False False False
False True False
True False False
True True True

The first two columns in the table above indicate the two inputs. The condition (A) and condition (B), each being a logical proposition. For example, (A) can be the logical proposition “it is raining outside” and (B)can be the logical proposition “the window is open”. The AND operator indicates that for two inputs, (A) and (B), the output/result will be True (last column of the table above) if both (A) and (B) are True, False otherwise.

The table above shows the possibilities of these two inputs ((A) and (B)). When (A=text{False}) and (B=text{False}), the result is False (first row). When (A=text{False}) and (B=text{True}), then the result is False (second row). And so on.

The OR Operator

Input (A)  Input (B) OR Outrput
False False False
False True True
True False True
True True True

The OR operator indicates that for two inputs, (A) and (B), the output/result will be True if either (A) or (B) is True, False if both are False. The table above shows the possibilities of these two inputs ((A) and (B)). When (A=text{False}) and (B = text{True}), the result is False (first row). When (A=text{False}) and (B = text{True}), then the result is True (second row). And so on.

The NOT Operator

Input (A) Outrput
True False
False True

The NOT operator is the simplest. It only takes a single input, the logical proposition (A). It simply inverts the input. If the input is True, it will invert it to False (first row), if the input is False it will invert it to True (second row).

Optional further reading

Logical propositions and logic operators are challenging topics, but very fundamental. If you find the topic interesting or challenging, and you would like to read more about it, you can find plenty of resources online.

This article is from the free online

An Introduction to Programming Using Python

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now