`bool`

¶Python has a type `bool`

for Boolean values. Unlike types `int`

, `float`

, and `str`

, which have thousands of values, type `bool`

has only two values: `True`

and `False`

.

Here are some examples of expressions that produce Booleans:

In [1]:

```
4 == 5.6
```

Out[1]:

In [2]:

```
5 == 5
```

Out[2]:

In [3]:

```
6.7 > 2
```

Out[3]:

In [4]:

```
4.5 <= 9.3
```

Out[4]:

In [5]:

```
27.4 != 27.5
```

Out[5]:

In the code above, we used several of Python's relational operators. Here is a summary:

Equal to: `==`

Not equal to: `!=`

Greater than: `>`

Greater than or equal to: `>=`

Less than: `<`

Less than or equal to: `<=`

There are three Boolean operators (the operands to these operators are type `bool`

): `not`

, `and`

, and `or`

.

In [6]:

```
not True
```

Out[6]:

In [7]:

```
not False
```

Out[7]:

Operator `and`

evaluates to `True`

if and only if both operands are `True`

.

In [8]:

```
True and True
```

Out[8]:

In [9]:

```
True and False
```

Out[9]:

In [10]:

```
False and True
```

Out[10]:

In [11]:

```
False and False
```

Out[11]:

Operator `or`

evaluates to `True`

if and only if at least one operator is `True`

.

In [12]:

```
True or True
```

Out[12]:

In [13]:

```
True or False
```

Out[13]:

In [14]:

```
False or True
```

Out[14]:

In [15]:

```
False or False
```

Out[15]:

Note: the Boolean operator `or`

isn't quite the same as the English "or".

In English, "For dessert, I'll have pie or I'll have ice cream", means that I'll only have one dessert.

In Python, it means that I'll have *at least* one dessert.

Consider this code fragment:

In [ ]:

```
grade1 = 80
grade2 = 90
not grade1 >= 50 or grade2 >= 50
```

What value does the expession produce: `True`

or `False`

?

The order of precedence for Boolean operators is `not`

, `and`

, and `or`

.

To make the order clear, we can add parentheses:

In [17]:

```
(not grade1 >= 50) or (grade2 >= 50)
```

Out[17]:

We can also use parentheses to change the order of operations:

In [18]:

```
not ((grade1 >= 50) or (grade2 >= 50))
```

Out[18]:

Write an English description of the situation in which the following code produces `True`

:

`not grade1 >= 50 or grade2 >= 50`

.

How do you express the English "I'll have pie or I'll have ice cream, but not both"? Define two Boolean variables:

In [19]:

```
pie = False
ice_cream = True
```

Write a Python expression that evaluates to `True`

if and only if exactly one of `pie`

and `ice_cream`

refers to `True`

.