From the course: Testing Python Data Science Code

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Truth values

Truth values

- [Narrator] In pytest, we use the assert statement to see if a condition is true or false. But what is true and what is false in Python? This is not as straightforward as it might seem. For a long time, we didn't have Boolean types. Only in 2002 which is also a long time ago, we got Booleans into the Python language. But the rules that predate the Boolean values still hold. So let's have a look. I'm doing X equal 20 and I'm going to assert that X is bigger than 10. I'm going to hit shift and enter and this is going to run it in a terminal. An assertion is not going to cause an exception. If a check that X is bigger than 10, I see true. However, if I'm going to assert X is bigger than a hundred, now I'm going to get an assertion error. And the reason is that X bigger than a hundred is false. But there are other things, so numbers, all the zero numbers in Python are false. So integers, floating points, complex…

Contents