+ 4
About python
What is the difference between assert and if statement?
2 Respostas
+ 7
"assert" throw an AssertionError if the following condition is false, while "if" execute statement / block statements if the following condition is true, with the possibility to put an "else" (and/or "elif" -- else if) statement after...
"assert" is usually used for test purposes, while "if" is used to control the program flow.
"assert" is quite equivalent to something like:
if not condition:
raise AssertionError()
... and:
assert True # do nothing
... while:
assert False # stop program with an error and output the traceback until you catch the error with a try/except exception handler
https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_if_else.htm
https://www.tutorialspoint.com/python/assertions_in_python.htm
https://www.pythonforbeginners.com/error-handling/python-try-and-except/
+ 3
"assert" throw an AssertionError if the following condition is false, while "if" execute statement / block statements if the following condition is true, with the possibility to put an "else" (and/or "elif" -- else if) statement after...
"assert" is usually used for test purposes, while "if" is used to control the program flow.
"assert" is quite equivalent to something like:
if not condition:
raise AssertionError()
... and:
assert True # do nothing
... while:
assert False # stop program with an error and output the traceback until you catch the error with a try/except exception handler
https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_if_else.htm
https://www.tutorialspoint.com/python/assertions_in_python.htm
https://www.pythonforbeginners.com/error-handling/python-try-and-except/