'Separate 0 from None [duplicate]

I want to implement next situation in my save function in model: if factor_rate exists in database ( not None) -> than do something. But in my case 0 is acceptable value for me, user can provide this value in form. And I don't know how to separate None from 0. Do you have any idea?

if self.factor_rate:
    self.status = False
else:
    self.status = True


Solution 1:[1]

You check with is None:

if self.factor_rate is None:
    self.status = False
else:
    self.status = True

or shorter:

self.status = self.factor_rate is not None

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Willem Van Onsem