I am having difficulties understanding the following block of Python code:
>>> before = None
>>> before = before or str.lower
>>> t = before("Some Text")
>>> t
'some text'
It seems that before
is a callable function here (in particular, callable(before)
returns True
) but I don't understand how this works. Can someone clearly explain the underlying logic? When I read the above block of code, my first though was that before
was a ordinary variable. Also, I am wondering if this is considered good coding practice as it's the first time I encounter this particular syntax?