What meaning is "if k in [0, len(n_trials) - 1] else None"?

Terry Reedy tjreedy at udel.edu
Sun Dec 4 14:14:14 EST 2016

On 12/3/2016 7:31 PM, Chris Angelico wrote:
> On Sun, Dec 4, 2016 at 11:10 AM, Terry Reedy <tjreedy at udel.edu> wrote:
>>> But the expression result isn't even used. So this is better written:
>> matplotlib.pyplot.xlabel sets x-axis scaling, with no documented return
>> value.
>> http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xlabel
>> If, as seems reasonable to assume, it returns None, the value of the
>> expression is 'None if x else None', which is to say, None.
> Hardly matters what the return value is, given that the code ignores it.

I was not clear enough.  To me, a 'conditional expression' that has an 
unconditional value is a bit confusing.  So I think the conditional 
side-effect would be better written the way you did regardless of the 
use or not of the value.  If the unconditional value were not ignored, I 
think it would be better used by itself.

Terry Jan Reedy

More information about the Python-list mailing list