Programmers use assert statements to verify expectations, such as the output of a function being tested.
Tags
#python #sicp
Question
What are assert statements used for?
Answer
?
Tags
#python #sicp
Question
What are assert statements used for?
Answer
Programmers use assert statements to verify expectations, such as the output of a function being tested.
If you want to change selection, open original toplevel document below and click on "Move attachment"
Parent (intermediate) annotation
Open it Assertions. Programmers use assert statements to verify expectations,
such as the output of a function being tested. An assert statement has an
expression in a boolean context, followed by a quoted line of text (single or
double quotes are both fine, but be consistent) that will be displayed if the
ex
Original toplevel document
1.5 Control most functions, which are meant to be general, tests
involve selecting and validating calls with specific argument values. Tests
also serve as documentation: they demonstrate how to call a function and what
argument values are appropriate.
<span>Assertions. Programmers use assert statements to verify expectations,
such as the output of a function being tested. An assert statement has an
expression in a boolean context, followed by a quoted line of text (single or
double quotes are both fine, but be consistent) that will be displayed if the
expression evaluates to a false value.
>>> assert fib(8) == 13, 'The 8th Fibonacci number should be 13'
When the expression being asserted evaluates to a true value, executing an
assert statement has no effect
Summary
status
not learned
measured difficulty
37% [default]
last interval [days]
repetition number in this series
0
memorised on
scheduled repetition
scheduled repetition interval
last repetition or drill
Details
No repetitions
Discussion
Do you want to join discussion? Click here to log in or create user.