There is no hard and fast rule. Here are some examples where I will use each:
Suppose I interact with some function that returns -1 on error and 0 on success. Such functions are fairly common in C, and they often occur in Python when using a library that wraps C functions. In this case, I would use if x:
On the other hand, if I am going to divide by x , and I want to make sure that x not 0 , then I will be explicit and write if x != 0 .
Generally, if I treat x as a bool in the whole function, then I will probably use if x: - even if I can prove that x will be int . If in the future I decide that I want to pass to the bool function (or some other type!), I will not need to change it.
On the other hand, if I really use x as an int , then I will most likely write 0 .
source share