Readability counts, was Re: Use of Lists, Tupples, or Sets in IF statement.

Peter Otten __peter__ at web.de
Tue Mar 15 04:29:50 EDT 2016


Rustom Mody wrote:

> Others have answered some parts
>>>> if x in x_list:
> ...     print("That is a fruit.")
> ... else:
> ...     print("That is not a fruit.")
> ...
> 
> However one can distribute the print out of the if; Thus
> 
>>>> "This is %s a fruit" % ("" if x in x_list else "not")

Which of the two versions will most readers grasp at first sight?
Which one is easier to modify so that it works for arbitrary attributes?
Which one is easier to internationalize?




More information about the Python-list mailing list