K
Kay Schluehr
Roy said:It is a deliberate and fundamental design decision in Python that
assignment is a statement, not an expression with side effects. This
means you often need an "extra" line compared to a classic C "assign
and test" idiom such as you have above. I, like you, often miss the
compactness of the C idiom, but there it is.
Hmm. A statement has side-effects but it returns no value. And yes, you
can create a name within an expression producing a value in Python,
using a list/generator comprehension. The solution to Bob's problem
would look like this:
if (I for I in (a.find("3"),) ) != -1:
print "It's here: ", I
else:
print "No 3's here"
Kay