Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Update 08-defensive.md #693
Thank you, @wachiuphd, for pointing out the problem!
However, we don't talk about
How about changing the assert statement to the following?
assert int(element) or element == 0
The other problem with this is that it doesn't really demonstrate "assert," which requires a True or False. For instance, the code
for element in [1,2,3.2,"a"]: assert int(element) or element == 0
gives an error totally unrelated to assert
This error occurs even before the "assert" part is called. You would get the same error from code without assert
for element in [1,2,3.2,"a"]: print(int(element))
edited by @maxim-belkin to stylize code/error blocks.
Yes and no.
Now, going back to the current episode: shall we do
>>> isinstance(True, int) True
I wonder what 3.2 cars look like...