π

All Subjects

Β >Β

β¨οΈΒ

AP Comp Sci P

Β >Β

π±

Big Idea 3: Algorithms and Programming

# Boolean Expressions

Minna Chow

### AP Computer Science PrinciplesΒ β¨οΈ

BookmarkedΒ 2.3kΒ β’Β 69Β resources
See Units

## Boolean Variables

Boolean variables can only represent the values true or false. Relational operators are used with Boolean values to test the relationship between two values.
Here are the relational operators you'll see on the test:
When you compare two values using a relational operator, the computer will return a Boolean value.
Take this Python example below:
```y = 5 x = 55 print (x > y)```
The computer will print the word True because 55 is greater than 5.

## Not, And, Or

Boolean values are also used with logical operators known as NOT, AND and OR. These can be used to combine multiple conditions, whereas relational operators can only evaluate one condition.
The NOT operator is used to reverse what the condition evaluates to. If a condition is true, the operator will evaluate to false, and vice versa.
```y = 5 x = 55 print (not y >= 5)```
In this case, the computer will print the word "False." y is equal to 5. This makes the condition trueβit's the not operator that reverses this so the computer returns false.
Here's the NOT operator in Pseudocode:
The AND operator is used to combine two conditions. The operator will only evaluate to true if both conditions are met.
```y = 5 x = 55 print (y >= 5 and x <= 44)```
The computer will print the word "False" because x is not less than or equal to 44, even though y equals 5.
Here's the AND operator in Pseudocode:
The OR operator also involves two conditions. In this case, the operator will evaluate to true if one condition or the other is met.
```y = 5 x = 55 print (y >= 5 or x <= 44)```
The computer will print the word "True" because, although the second condition isn't met, the first one is.
Here's the OR operator in Pseudocode:

Image source: College Board CED

Logical operators evaluate either Boolean expressions or a single Boolean value.

Thousands of students are studying with us for the AP Computer Science Principles exam.
Studying with Hours = the ultimate focus mode
Start a free study session
##### π Are you ready for college apps?
Take this quiz and find out!
Start Quiz
Browse Study Guides By Unit
πΉBig Idea 1: Creative Development
βοΈBig Idea 2: Data
π±Big Idea 3: Algorithms and Programming
π₯Big Idea 4: Computer Systems and Networks
β¨οΈBig Idea 5: Impact of Computing
βοΈBlogs
πExam Prep