A C-like if statement

Antoon Pardon apardon at forel.vub.ac.be
Fri Feb 24 06:49:31 EST 2006


Op 2006-02-23, Roy Smith schreef <roy at panix.com>:
> Bob Greschke <bob at passcal.nmt.edu> wrote:
>>I miss being able to do something like this in Python
>>
>>1f (I = a.find("3")) != -1:
>>    print "It's here: ", I
>>else:
>>    print "No 3's here"
>>
>>where I gets assigned the index returned by find() AND the if statement gets 
>>to do its job in the same line.  Then you don't have to have another like 
>>that specifically gets the index of the "3".  Is there a way to do this in 
>>Python?
>
> It is a deliberate and fundamental design decision in Python that
> assignment is a statement, not an expression with side effects.

The only motivation I have heard for this decision is to easily
find typo related bugs. I can hardly find that a fundamental
design decision.

-- 
Antoon Pardon



More information about the Python-list mailing list