-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassertions.py
More file actions
28 lines (21 loc) · 657 Bytes
/
Copy pathassertions.py
File metadata and controls
28 lines (21 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# assertions.py
mylist = [1, 2, 3] # pretend this comes from an external source
assert 4 == len(mylist) # this will break
for position in range(4):
print(mylist[position])
"""
$ python assertions.py
Traceback (most recent call last):
File "assertions.py", line 4, in <module>
assert 4 == len(mylist) # this will break
AssertionError
"""
# asserts with message
assert 4 == len(mylist), f"Mylist has {len(mylist)} elements"
"""
$ python assertions.py
Traceback (most recent call last):
File "assertions.py", line 19, in <module>
assert 4 == len(mylist), f"Mylist has {len(mylist)} elements"
AssertionError: Mylist has 3 elements
"""