This is an old style way to use ternary condition operator.
It has nothing related to print
.
See this answer.
In most cases it does the same as this code
print(T and sorted(sorted(T,reverse=True),key=abs)[0] or 0)
print(sorted(sorted(T,reverse=True),key=abs)[0] if T else 0)
It works because of the way and
and or
works in Python - they do not return bool
, but they return either first or second operand, depending if it casts to True or False.
This answer has more details.
Basically it's two operation
first = T and sorted(sorted(T,reverse=True),key=abs)[0]
and
Return the first Falsy value if there are any, else return the last value in the expression.
So it either returns []
(possible Falsy value for T), or first element in sorted list.
result = first or 0
or
Return the first Truthy value if there are any, else return the last value in the expression.
So if T is Truthy, we already have a Truthy value in first
(unless it's 0, which is special case, but 0 or 0
is 0
anyway), it will be returned.
If T
is []
- it will return 0.