int(value or 0)
This will use 0 in the case when you provide any value that Python considers False
, such as None, 0, [], "", etc. Since 0 is False
, you should only use 0 as the alternative value (otherwise you will find your 0s turning into that value).
int(0 if value is None else value)
This replaces only None
with 0. Since we are testing for None
specifically, you can use some other value as the replacement.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…