booleans
what are booleans?
There are only 2 booleans - True and False. I can use the assertFalse and assertTrue methods to test which of the basic data structures seen so far - integers, floats, strings, tuples, lists, sets and dictionaries, are True or False in Python
preview
Here are the tests I have by the end of the chapter
1import unittest
2
3
4class TestBooleans(unittest.TestCase):
5
6 def test_what_is_false(self):
7 self.assertIsInstance(False, bool)
8 self.assertFalse(False)
9 self.assertFalse(None)
10 self.assertFalse(0)
11 self.assertFalse(0.0)
12 self.assertFalse(str())
13 self.assertFalse(tuple())
14 self.assertFalse(list())
15 self.assertFalse(set())
16 self.assertFalse(dict())
17
18 def test_what_is_true(self):
19 self.assertIsInstance(True, bool)
20 self.assertTrue(True)
21 self.assertTrue(-1)
22 self.assertTrue(1)
23 self.assertTrue(-0.1)
24 self.assertTrue(0.1)
25 self.assertTrue('text')
26 self.assertTrue((1, 2, 3, 'n'))
27 self.assertTrue([1, 2, 3, 'n'])
28 self.assertTrue({1, 2, 3, 'n'})
29 self.assertTrue({'key': 'value'})
30
31
32# NOTES
33# a dictionary with things is true
34# a set with things is true
35# a list with things is true
36# a tuple with things is true
37# a string with things is true
38# positive and negative numbers are true
39# True is true
40# True is not false
41# True is a boolean
42# the empty dictionary is false
43# the empty set is false
44# the empty list is false
45# the empty tuple is false
46# the empty string is false
47# 0 is false
48# None is false
49# False is false
50# False is not true
51# False is a boolean
52
53
54# Exceptions seen
55# AssertionError
questions about Booleans
Here are the questions you can answer after going through this chapter
start the project
I name this project
booleansI open a terminal
then I make a directory for the project
mkdir booleansthe terminal goes back to the command line
.../pumping_pythonI change directory to the project
cd booleansthe terminal shows I am now in the
booleansfolder.../pumping_python/booleansI make a folder for the source code
mkdir srcthe terminal goes back to the command line
.../pumping_python/booleansI use touch to make an empty file for the program in the
srcfoldertouch src/booleans.pyon Windows without Windows Subsystem for Linux use
New-Item src/booleans.pyinstead oftouch src/booleans.pyNew-Item src/booleans.pythe terminal goes back to the command line
.../pumping_python/booleansI make a directory for the tests
mkdir teststhe terminal goes back to the command line
I use touch to make an empty file in the
testsfolder to tell Python that it is a Python packageAttention
use 2 underscores (__) before and after
initfor__init__.pynot_init_.pytouch tests/__init__.pyon Windows without Windows Subsystem for Linux use
New-Item tests/__init__.pyinstead oftouch tests/__init__.pyNew-Item tests/__init__.pythe terminal goes back to the command line
I make an empty file for the actual test
touch tests/test_booleans.pyon Windows without Windows Subsystem for Linux use
New-Item tests/test_booleans.pyinstead oftouch tests/test_booleans.pyNew-Item tests/test_booleans.pythe terminal goes back to the command line
I open
test_booleans.pyin the editor of the Integrated Development Environment (IDE)Tip
I can open a file from the terminal in Visual Studio Code by typing
codeand the name of the file withcode tests/test_booleans.pytest_booleans.pyopens up in the editorI add the first failing test to
test_booleans.py1import unittest 2 3 4class TestBooleans(unittest.TestCase): 5 6 def test_failure(self): 7 self.assertFalse(True)I make a virtual environment in the terminal
python3 -m venv .venvon Windows without Windows Subsystem for Linux use
python3 -m venv .venvinstead ofpython3 -m venv .venvpython -m venv .venvthe terminal takes some time then goes back to the command line
I activate the virtual environment
source .venv/bin/activateon Windows without Windows Subsystem for Linux use
.venv/bin/activate.ps1instead ofsource .venv/bin/activate.venv/scripts/activate.ps1the terminal shows
(.venv) .../pumping_python/booleansI upgrade the Python package manager (pip) to the latest version
python3 -m pip install --upgrade pipthe terminal shows pip being uninstalled then installs the latest version or shows that it is already the latest version
I make a
requirements.txtfile for the Python programs my project needsecho "pytest-watch" > requirements.txtthe terminal goes back to the command line
I use pip to use the requirements file to install
pytest-watchpython3 -m pip install --requirement requirements.txton Windows without Windows Subsystem for Linux use
python -m pip install --requirement requirements.txtinstead ofpython3 -m pip install --requirement requirements.txtpython -m pip install --requirement requirements.txtthe terminal shows pip downloads and installs the Python programs that pytest-watch needs to run
I use pytest-watch to run the test
pytest-watchthe terminal shows
================================ FAILURES ================================ ______________________ TestBooleans.test_failure ________________________ self = <tests.test_booleans.TestBooleans testMethod=test_failure> def test_failure(self): > self.assertFalse(True) E AssertionError: True is not false tests/test_booleans.py:7: AssertionError ======================== short test summary info ========================= FAILED tests/test_booleans.py::TestBooleans::test_failure - AssertionError: True is not false =========================== 1 failed in X.YZs ============================I hold ctrl (Windows/Linux) or
option or command(MacOS) on the keyboard and use the mouse to click ontests/test_booleans.py:7to open it in the editorI add AssertionError to the list of Exceptions seen in
test_booleans.py7 self.assertFalse(True) 8 9 10# Exceptions seen 11# AssertionErrorthen I change True to False in the assertion
7 self.assertFalse(False)the test passes
test_what_is_false
RED: make it fail
I change
test_failuretotest_what_is_false, then use the assertNotIsInstance method from testing None to check if False is a child/instance of the bool class expecting a failure1import unittest 2 3 4class TestBooleans(unittest.TestCase): 5 6 def test_what_is_false(self): 7 self.assertNotIsInstance(False, bool)the terminal shows AssertionError
AssertionError: False is an instance of <class 'bool'>
GREEN: make it pass
I change assertNotIsInstance to assertIsInstance
7 self.assertIsInstance(False, bool)
the test passes and I add a note
10# NOTES
11# False is a boolean
12
13
14# Exceptions seen
so far this is going over what I already know from testing None
test_what_is_true
I do the same thing with True
RED: make it fail
I add another failing test
6 def test_what_is_false(self):
7 self.assertIsInstance(False, bool)
8
9 def test_what_is_true(self):
10 self.assertNotIsInstance(True, bool)
11
12
13# NOTES
the terminal shows AssertionError
AssertionError: True is an instance of <class 'bool'>
GREEN: make it pass
I change the assert method
10 self.assertIsInstance(True, bool)the test passes
I add another note
13# NOTES 14# True is a boolean 15# False is a boolean 16 17 18# Exceptions seen
REFACTOR: make it better
I add a failing line to
test_what_is_true9 def test_what_is_true(self): 10 self.assertIsInstance(True, bool) 11 self.assertTrue(False) 12 13 14# NOTESthe terminal shows AssertionError
AssertionError: False is not trueI change assertTrue to assertFalse
9 def test_what_is_true(self): 10 self.assertIsInstance(True, bool) 11 self.assertFalse(False)the test passes
I add a note
13# NOTES 14# True is a boolean 15# False is not true 16# False is a boolean 17 18 19# Exceptions seen 20# AssertionErrorI move the line from
test_what_is_trueto thetest_what_is_falsemethod6 def test_what_is_false(self): 7 self.assertIsInstance(False, bool) 8 self.assertFalse(False) 9 10 def test_what_is_true(self): 11 self.assertIsInstance(True, bool)Tip
You do not need to copy and paste to move a line. If you are using Visual Studio Code you can use alt (Windows/Linux) or option (MacOS) with the up/down arrows on the keyboard to move a line up or down
I add a note
14# NOTES 15# True is a boolean 16# False is false 17# False is not true 18# False is a boolean 19 20 21# Exceptions seenI add a failing line to
test_what_is_false6 def test_what_is_false(self): 7 self.assertIsInstance(False, bool) 8 self.assertFalse(False) 9 self.assertFalse(True)the terminal shows AssertionError
AssertionError: True is not falseI change assertFalse to assertTrue
6 def test_what_is_false(self): 7 self.assertIsInstance(False, bool) 8 self.assertFalse(False) 9 self.assertTrue(True)the test passes
I add a note
15# NOTES 16# True is not false 17# True is a boolean 18# False is false 19# False is not true 20# False is a boolean 21 22 23# Exceptions seenI move the line from
test_what_is_falseto thetest_what_is_truemethod6 def test_what_is_false(self): 7 self.assertIsInstance(False, bool) 8 self.assertFalse(False) 9 10 def test_what_is_true(self): 11 self.assertIsInstance(True, bool) 12 self.assertTrue(True)I add another note
15# NOTES 16# True is true 17# True is not false 18# True is a boolean 19# False is false 20# False is not true 21# False is a boolean 22 23 24# Exceptions seen 25# AssertionError
All of this is still a repetition of what I did with AssertionError. Next up, I test the other Python basic data types to see which of are False or True
is None False or True?
RED: make it fail
I add a line in test_what_is_true to test if None is True
10 def test_what_is_true(self):
11 self.assertIsInstance(True, bool)
12 self.assertTrue(True)
13 self.assertTrue(None)
the terminal shows AssertionError
AssertionError: None is not true
GREEN: make it pass
I change the method
13 self.assertFalse(None)
the test passes
REFACTOR: make it better
I move the line from test_what_is_true to test_what_is_false
6 def test_what_is_false(self):
7 self.assertIsInstance(False, bool)
8 self.assertFalse(False)
9 self.assertFalse(None)
10
11 def test_what_is_true(self):
12 self.assertIsInstance(True, bool)
13 self.assertTrue(True)
I add a note
16# NOTES
17# True is true
18# True is not false
19# True is a boolean
20# None is false
21# False is false
22# False is not true
23# False is a boolean
24
25
26# Exceptions seen
None is False though I learned in test_assertion_error_w_false that False is not None
is an integer False or True?
RED: make it fail
I add a failing line test_what_is_false to see if an integer (a whole number) is False
6 def test_what_is_false(self):
7 self.assertIsInstance(False, bool)
8 self.assertFalse(False)
9 self.assertFalse(None)
10 self.assertFalse(-1)
11
12 def test_what_is_true(self):
the terminal shows AssertionError
AssertionError: -1 is not false
GREEN: make it pass
I change the method
10 self.assertTrue(-1)
the test passes
REFACTOR: make it better
I move the line from
test_what_is_falsetotest_what_is_true6 def test_what_is_false(self): 7 self.assertIsInstance(False, bool) 8 self.assertFalse(False) 9 self.assertFalse(None) 10 11 def test_what_is_true(self): 12 self.assertIsInstance(True, bool) 13 self.assertTrue(True) 14 self.assertTrue(-1)I use
-1for all the integers (whole numbers) that are smaller than0. Negative integers are True in PythonI add a new failing line to
test_what_is_trueto see if0is True14 self.assertTrue(-1) 15 self.assertTrue(0)the terminal shows AssertionError
AssertionError: 0 is not trueI change the method to assertFalse
15 self.assertFalse(0)the test passes
I move the line to
test_what_is_false7 self.assertIsInstance(False, bool) 8 self.assertFalse(False) 9 self.assertFalse(None) 10 self.assertFalse(0) 11 12 def test_what_is_true(self):I add another failing line to
test_what_is_falseto see if1is False10 self.assertFalse(0) 11 self.assertFalse(1) 12 13 def test_what_is_true(self): 14 self.assertIsInstance(True, bool)the terminal shows AssertionError
AssertionError: 1 is not falseI change the method
11 self.assertTrue(1)the test passes
I move the line to
test_what_is_true10 self.assertFalse(0) 11 12 def test_what_is_true(self): 13 self.assertIsInstance(True, bool) 14 self.assertTrue(True) 15 self.assertTrue(-1) 16 self.assertTrue(1)I use
1for all the integers (whole numbers) that are bigger than0. Positive and negative integers are True in PythonI add notes
19# NOTES 20# positive and negative integers are true 21# True is true 22# True is not false 23# True is a boolean 24# 0 is false 25# None is false 26# False is false 27# False is not true 28# False is a boolean 29 30 31# Exceptions seen 32# AssertionError
is a float False or True?
RED: make it fail
I add a line to test if floats (binary floating point decimal numbers) are False in test_what_is_false
10 self.assertFalse(0)
11 self.assertFalse(-0.1)
12
13 def test_what_is_true(self):
the terminal shows AssertionError
AssertionError: -0.1 is not false
GREEN: make it pass
I change the method
11 self.assertTrue(-0.1)the test passes
I move the line to
test_what_is_true14 self.assertTrue(True) 15 self.assertTrue(-1) 16 self.assertTrue(1) 17 self.assertTrue(-0.1)I use
-0.1for all the floating point numbers that are smaller than0.0. Negative floats are True in Python
REFACTOR: make it better
I add another failing line to
test_what_is_trueto see if0.0is True17 self.assertTrue(-0.1) 18 self.assertTrue(0.0)the terminal shows AssertionError
AssertionError: 0.0 is not trueI change the method
18 self.assertFalse(0.0)the test passes
I move the line to
test_what_is_false7 def test_what_is_false(self): 8 self.assertIsInstance(False, bool) 9 self.assertFalse(False) 10 self.assertFalse(None) 11 self.assertFalse(0) 12 self.assertFalse(0.0) 13 14 def test_what_is_true(self):I add another line to
test_what_is_falseto see if0.1is False in Python11 self.assertFalse(0.0) 12 self.assertFalse(0.1) 13 14 def test_what_is_true(self): 15 self.assertIsInstance(True, bool)the terminal shows AssertionError
AssertionError: 0.1 is not falseI change the method
15 self.assertTrue(0.1)the test passes
I move the line to
test_what_is_true11 self.assertFalse(0.0) 12 13 def test_what_is_true(self): 14 self.assertIsInstance(True, bool) 15 self.assertTrue(True) 16 self.assertTrue(-1) 17 self.assertTrue(1) 18 self.assertTrue(-0.1) 19 self.assertTrue(0.1) 20 21 22# NOTESI use
0.1for all the floating point numbers that are bigger than0.0. Positive and negative floats are also True in PythonI add notes
22# NOTES 23# positive and negative floats are true 24# positive and negative integers are true 25# True is true 26# True is not false 27# True is a boolean 28# 0.0 is false 29# 0 is false 30# None is false 31# False is false 32# False is not true 33# False is a booleanI make the new notes simpler because floats and integers are numbers and
0.0is the same as0even though they are different types22# NOTES 23# positive and negative numbers are true 24# True is true 25# True is not false 26# True is a boolean 27# 0 is false 28# None is false 29# False is false 30# False is not true 31# False is a boolean 32 33 34# Exceptions seen
is a string False or True?
RED: make it fail
I add a failing line to test_what_is_true to test if a string (anything in quotes) is True
13 def test_what_is_true(self):
14 self.assertIsInstance(True, bool)
15 self.assertTrue(True)
16 self.assertTrue(-1)
17 self.assertTrue(1)
18 self.assertTrue(-0.1)
19 self.assertTrue(0.1)
20 self.assertTrue(str())
21
22
23# NOTES
the terminal shows AssertionError
AssertionError: '' is not true
GREEN: make it pass
I change the method
20 self.assertFalse(str())
the test passes
REFACTOR: make it better
I move the line to
test_what_is_false11 self.assertFalse(0.0) 12 self.assertTrue(str()) 13 14 def test_what_is_true(self):I add a failing line to
test_what_is_false11 self.assertFalse(0.0) 12 self.assertFalse(str()) 13 self.assertFalse('text')the terminal shows AssertionError
AssertionError: 'text' is not falseI change the method
13 self.assertTrue('text')the test passes
I move the line to
test_what_is_true12 self.assertFalse(str()) 13 14 def test_what_is_true(self): 15 self.assertIsInstance(True, bool) 16 self.assertTrue(True) 17 self.assertTrue(-1) 18 self.assertTrue(1) 19 self.assertTrue(-0.1) 20 self.assertTrue(0.1) 21 self.assertTrue('text') 22 23 24# NOTESI add notes
24# NOTES 25# a string with things is true 26# positive and negative numbers are true 27# True is true 28# True is not false 29# True is a boolean 30# the empty string is false 31# 0 is false 32# None is false 33# False is false 34# False is not true 35# False is a boolean 36 37 38# Exceptions seen 39# AssertionError
is a tuple False or True?
RED: make it fail
I add a line to test_what_is_true to see if a tuple (anything in parentheses (())) is True
14 def test_what_is_true(self):
15 self.assertIsInstance(True, bool)
16 self.assertTrue(True)
17 self.assertTrue(-1)
18 self.assertTrue(1)
19 self.assertTrue(-0.1)
20 self.assertTrue(0.1)
21 self.assertTrue('text')
22 self.assertTrue(tuple())
23
24
25# NOTES
The terminal shows AssertionError
AssertionError: () is not true
GREEN: make it pass
I change the assert method
22 self.assertFalse(tuple())the test passes
I move the line to
test_what_is_false6 def test_what_is_false(self): 7 self.assertIsInstance(False, bool) 8 self.assertFalse(False) 9 self.assertFalse(None) 10 self.assertFalse(0) 11 self.assertFalse(0.0) 12 self.assertFalse(str()) 13 self.assertFalse(tuple()) 14 15 def test_what_is_true(self):
REFACTOR: make it better
I add another line to
test_what_is_falseto see if a tuple with things is False13 self.assertFalse(tuple()) 14 self.assertFalse((1, 2, 3, 'n'))the terminal shows AssertionError
AssertionError: (1, 2, 3, 'n') is not falseI change the method
14 self.assertTrue((1, 2, 3, 'n'))the test passes
I move the line to
test_what_is_true13 self.assertFalse(tuple()) 14 15 def test_what_is_true(self): 16 self.assertIsInstance(True, bool) 17 self.assertTrue(True) 18 self.assertTrue(-1) 19 self.assertTrue(1) 20 self.assertTrue(-0.1) 21 self.assertTrue(0.1) 22 self.assertTrue('text') 23 self.assertTrue((1, 2, 3, 'n')) 24 25 26# NOTESTip
If you are using Visual Studio Code you can use alt (Windows/Linux) or option (MacOS) with the up/down arrows on the keyboard to move a line up or down
I add notes
26# NOTES 27# a tuple with things is true 28# a string with things is true 29# positive and negative numbers are true 30# True is true 31# True is not false 32# True is a boolean 33# the empty tuple is false 34# the empty string is false 35# 0 is false 36# None is false 37# False is false 38# False is not true 39# False is a boolean
is a list False or True?
RED: make it fail
I add a line to test if a list (anything in square brackets ([])) is True
23 self.assertTrue((1, 2, 3, 'n'))
24 self.assertTrue(list())
the terminal shows AssertionError
AssertionError: [] is not true
GREEN: make it pass
I change the method
24 self.assertFalse(list())the test passes
I move the line to
test_what_is_false13 self.assertFalse(tuple()) 14 self.assertFalse(list()) 15 16 def test_what_is_true(self):
REFACTOR: make it better
I add another line to
test_what_is_falseto see if a list with things is False14 self.assertFalse(list()) 15 self.assertFalse([1, 2, 3, 'n']) 16 17 def test_what_is_true(self): 18 self.assertIsInstance(True, bool)the terminal shows AssertionError
AssertionError: [1, 2, 3, 'n'] is not falseI change the method
15 self.assertTrue([1, 2, 3, 'n'])the test passes
I move the line to
test_what_is_true14 self.assertFalse(list()) 15 16 def test_what_is_true(self): 17 self.assertIsInstance(True, bool) 18 self.assertTrue(True) 19 self.assertTrue(-1) 20 self.assertTrue(1) 21 self.assertTrue(-0.1) 22 self.assertTrue(0.1) 23 self.assertTrue('text') 24 self.assertTrue((1, 2, 3, 'n')) 25 self.assertTrue([1, 2, 3, 'n']) 26 27 28# NOTESI add notes
28# NOTES 29# a list with things is true 30# a tuple with things is true 31# a string with things is true 32# positive and negative numbers are true 33# True is true 34# True is not false 35# True is a boolean 36# the empty list is false 37# the empty tuple is false 38# the empty string is false 39# 0 is false 40# None is false 41# False is false 42# False is not true 43# False is a boolean 44 45 46# Exceptions seen 47# AssertionError
I can see a pattern forming
is a set False or True?
RED: make it fail
I add a line to in test_what_is_true to see if a set is True
25 self.assertTrue([1, 2, 3, 'n'])
26 self.assertTrue(set())
27
28
29# NOTES
the terminal shows AssertionError
AssertionError: set() is not true
GREEN: make it pass
I change the method
26 self.assertFalse(set())the test passes
I move the line to
test_what_is_false14 self.assertFalse(list()) 15 self.assertFalse(set()) 16 17 def test_what_is_true(self):
REFACTOR: make it better
I add another line to
test_what_is_falseto see if a set with things is False15 self.assertFalse(set()) 16 self.assertFalse({1, 2, 3, 'n'}) 17 18 def test_what_is_true(self):the terminal shows AssertionError
AssertionError: {1, 2, 3, 'n'} is not falseI change the method
16 self.assertTrue({1, 2, 3, 'n'})the test passes
I move the line to
test_what_is_true15 self.assertFalse(set()) 16 17 def test_what_is_true(self): 18 self.assertIsInstance(True, bool) 19 self.assertTrue(True) 20 self.assertTrue(-1) 21 self.assertTrue(1) 22 self.assertTrue(-0.1) 23 self.assertTrue(0.1) 24 self.assertTrue('text') 25 self.assertTrue((1, 2, 3, 'n')) 26 self.assertTrue([1, 2, 3, 'n']) 27 self.assertTrue({1, 2, 3, 'n'}) 28 29 30# NOTESI add to the notes
30# NOTES 31# a set with things is true 32# a list with things is true 33# a tuple with things is true 34# a string with things is true 35# positive and negative numbers are true 36# True is true 37# True is not false 38# True is a boolean 39# the empty set is false 40# the empty list is false 41# the empty tuple is false 42# the empty string is false 43# 0 is false 44# None is false 45# False is false 46# False is not true 47# False is a boolean 48 49 50# Exceptions seen 51# AssertionError
is a dictionary False or True?
RED: make it fail
I add a line to test_what_is_true to test if a dictionary is True
27 self.assertTrue({1, 2, 3, 'n'})
28 self.assertTrue(dict())
29
30
31# NOTES
the terminal shows AssertionError
AssertionError: {} is not true
the empty dictionary is NOT True
GREEN: make it pass
I change assertTrue to assertFalse
28 self.assertFalse(dict())the test passes
I move the line to the
test_what_is_falsemethod6 def test_what_is_false(self): 7 self.assertIsInstance(False, bool) 8 self.assertFalse(False) 9 self.assertFalse(None) 10 self.assertFalse(0) 11 self.assertFalse(0.0) 12 self.assertFalse(str()) 13 self.assertFalse(tuple()) 14 self.assertFalse(list()) 15 self.assertFalse(set()) 16 self.assertFalse(dict()) 17 18 def test_what_is_true(self):
REFACTOR: make it better
I add another line to test if a dictionary with things is also False
14 self.assertFalse(list()) 15 self.assertFalse(set()) 16 self.assertFalse(dict()) 17 self.assertFalse({'key': 'value'})the terminal shows AssertionError
AssertionError: {'key': 'value'} is not falsea dictionary with things is NOT False
I change assertFalse to assertTrue
17 self.assertTrue({'key': 'value'})the test passes
I move the line to the
test_what_is_truemethod6 def test_what_is_false(self): 7 self.assertIsInstance(False, bool) 8 self.assertFalse(False) 9 self.assertFalse(None) 10 self.assertFalse(0) 11 self.assertFalse(0.0) 12 self.assertFalse(str()) 13 self.assertFalse(tuple()) 14 self.assertFalse(list()) 15 self.assertFalse(set()) 16 self.assertFalse(dict()) 17 18 def test_what_is_true(self): 19 self.assertIsInstance(True, bool) 20 self.assertTrue(True) 21 self.assertTrue(-1) 22 self.assertTrue(1) 23 self.assertTrue(-0.1) 24 self.assertTrue(0.1) 25 self.assertTrue('text') 26 self.assertTrue((1, 2, 3, 'n')) 27 self.assertTrue([1, 2, 3, 'n']) 28 self.assertTrue({1, 2, 3, 'n'}) 29 self.assertTrue({'key': 'value'}) 30 31 32# NOTESI add the last 2 notes
32# NOTES 33# a dictionary with things is true 34# a set with things is true 35# a list with things is true 36# a tuple with things is true 37# a string with things is true 38# positive and negative numbers are true 39# True is true 40# True is not false 41# True is a boolean 42# the empty dictionary is false 43# the empty set is false 44# the empty list is false 45# the empty tuple is false 46# the empty string is false 47# 0 is false 48# None is false 49# False is false 50# False is not true 51# False is a boolean 52 53 54# Exceptions seen 55# AssertionError
close the project
I close the file(s) I have open in the editor(s)
I click in the terminal and exit the tests with ctrl+c on the keyboard
I deactivate the virtual environment
deactivatethe terminal goes back to the command line,
(.venv)is no longer on the left side.../pumping_python/booleansI change directory to the parent of
booleanscd ..the terminal shows
.../pumping_pythonI am back in the
pumping_pythondirectory
review
From the tests I can see that in Python
a container with things is True
an empty container is False
positive and negative numbers are True
0is False
these things come in handy when I write conditions in programs, because I can make decisions on whether the data is empty or has something in it
How many questions can you answer after going through this chapter?
code from the chapter
what is next?
you now know
Would you like to test the truth table? It will help you understand writing programs that make decisions based on conditions