?: in Python
Andy Leszczynski
yahoo at nospam.leszczynscy
Sat Dec 17 21:47:14 EST 2005
Steven D'Aprano wrote:
> On Wed, 14 Dec 2005 20:17:28 -0500, Andy Leszczynski wrote:
>
>
>>I can tell you what is not elegant in the if else: approach. It is
>>logically a one operation while you are forced to use varaible "a"
>>twice. Fundamental flaw IMO.
>
>
> "Logically" one operation?
>
> def twenty_countries_in_seven_days_bus_tour():
> ...
> if today() == Monday:
> write_postcode_to_mother("We must be in Belgium.")
> else:
> get_back_on_the_bus("Not again!")
> ...
>
>
> if...else expressions with a single operation are just a special case.
> Perhaps a common special case, but still a special case.
>
>
First:
"Special cases aren't special enough to break the rules.
Although practicality beats purity."
Second, let's look at again:
>if condition:
> a=1
>else:
> a=2
The primer meaning behind that is that I want to assign something to a.
What I want to assign is secondary issue. I do not like C syntax of ?:
either but I think it is just practical and self-explanatory.
A.
More information about the Python-list
mailing list