Boolean Logic, Operators & Expressions

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: What is a Computer Algorithm? - Design, Examples & Optimization

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
Your next lesson will play in 10 seconds
  • 0:06 Boolean Data Type
  • 1:14 Boolean Expression
  • 2:51 Boolean Operators
  • 6:07 Lesson Summary
Save Save Save

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Log in or Sign up

Speed Speed

Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Paul Zandbergen

Paul has a PhD from the University of British Columbia and has taught Geographic Information Systems, statistics and computer programming for 15 years.

Programming uses Booleans, which are used to represent values of true and false. Many operations use Boolean logic. Learn how Boolean operators and expressions are used.

Boolean Data Type

Programming uses a number of different data types. The data type of an object determines what type of values an object can have and what operations can be performed on the object. Commonly used data types include strings, numbers, lists and arrays. This lesson will look more closely at one data type that is widely used: Boolean data.

The Boolean data type can only represent two values: true or false. Typically, a 1 is used to represent true, and a 0 is used to represent false. Boolean data is widely used when working with conditions. If you want to ask a basic question and the answer can be only yes or no, you need a Boolean. The term 'Boolean' comes from a 19th century mathematician called George Boole who came up with the original idea of what we now call Boolean logic in his book The Laws of Thought.

Boolean Expression

Boolean data are used in Boolean expressions, which are expressions in a programming language that produce a Boolean value. An expression in programming is any combination of values, variables and operators that produce a new value. For example, 2 + 3 is an expression, and the result is the new value 5. When you use a Boolean expression, the only logical result can be true or false.

Consider the following example where a user inputs two values, and a computer program determines whether the first one is smaller than the second one or not.

x = 8
y = 7
x < y

In this example, the part 'x < y' is the Boolean expression. You are asking whether x is less than y, and the answer can only be a yes or a no - which means true or false in programming. In the example, the value of x is in fact not smaller than the value of y, and the program therefore results in a Boolean value of false. In programming language, we say that the expression is evaluated and returns a value of false.

The Boolean type is the primary result of conditional statements, which are used to control workflow in program. For example, if a particular condition is true, then do this; if the condition is false, then do something else.

Boolean Operators

In addition to Boolean data, there are Boolean operators, which are used to carry out Boolean algebra. There are three main Boolean operators: AND, OR and NOT. The first two are used to combine two expressions; the third is used as a negation operator. Let's look at each of these in more detail.

The simplest Boolean operator is the NOT operator. It simply turns true into false, and vice versa. Consider the following example.

x = 8
y = 7
NOT (x < y)

This returns a value of true. We know that x is greater than y, so the expression 'x < y' returns a value of false. The NOT operator turns this into a value of true.

Now, let's look at the AND and OR operators. The AND operator compares two expressions. It only returns a value of true if both expressions are true; otherwise, it returns a value of false. Consider the following example:

x = 8
y = 7
z = 6
(x < y) AND (z < y)

The first expression is false, and the second expression is true. The AND operator combines both expressions, and since one of them is false, the final result is false.

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account