Empty string in Python is equivalent of a False boolean value, the same way as an empty list. The line you've presented is Python version of a ternary operator (as noted in the comment below, nowadays an obsolete construction, as Python now has a real ternary operator). It is based on three rules:
- for
a and b if a is False then b won't be evaluated
- for
a or b if a is True then b won't be evaluated
- the value of a logical clause is the value of its most recently evaluated expression
If parameter evaluates to True the second part of the and clause will get evaluated: (" " + parameter). So it will add leading space to a parameter if it's not an empty string. The second part of the or clause won't get evaluated, as you can already tell the whole expression is True (True or anything is always True).
If parameter is False (empty string in this context) the second part of the and clause won't get evaluated, as you can already tell it's being False (False and anything is always False). Therefore the second part of the or clause gets evaluated returning an empty string.
You can write it in a more verbose way:
if parameter:
return " " + parameter
else:
return ""