Python ‘If not’ syntax [duplicate]

I’m a bit confused about how/why so many python developers use if not in their conditional statements.

for example, lets say we had a function,

def foo(bar = None):
    if not bar:
        bar = 2

But why go about this way? I mean, wouldn’t doing if bar != None or if bar is not Nonebe more explicit? What does if not try to say?

1 Answer
1

Leave a Comment