Why prefer != over <> for Python 3.0?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Mar 30 07:07:10 EDT 2008


On Sat, 29 Mar 2008 22:11:33 -0700, hdante wrote:

>  BTW, my opinion is that it's already time that programmer editors
> have input methods advanced enough for generating this:
> 
> if x ≠ 0:
>     ∀y ∈ s:
>         if y ≥ 0: f1(y)
>         else: f2(y)
> 
> ;-)

Back in the 1990s, Apple's Hypercard accepted ≠ for "not equal". Of 
course, Macs made it easy to type such special characters. By memory you 
held down the Option key and typed an equals sign. For ≥ you used Option 
and less-than. That worked in *any* Mac application.

Ah, glory days.

But I digress. In Python we can write the above as:


if x != 0:
    [f1(y) if y >= 0 else f2(y) for y in s]


which for those not trained in algebra is probably more readable.



-- 
Steven



More information about the Python-list mailing list