In Javascript, I can do this:
function A(x) { return x || 3; }
This returns 3 if x is an "invalid" value, for example 0, null, false, and returns x otherwise. This is useful for empty arguments, for example. I can do A() and it will be evaluated as 3.
Does Python have an equivalent? I think I could make one of the ternary operator a if b else c , but I wondered what people use for this.
source share