auto increment operator??

Fredrik Lundh effbot at telia.com
Mon May 29 20:01:39 EDT 2000


Bob van der Poel wrote:
> First off, why are there no operators equivalent to C's
> ++, --, +=, etc.? Very useful, and readable. Writing things
> like: 'var = var+1' is getting old real fast.

if you write things like "var = var + 1" a lot, you might be
missing some important python idioms...

here are a few, in no specific order:

    for item in sequence:
        ...

    sequence = map(operation, sequence)

    sequence.append(item)

    for index in range(size):
        ...

    for item1, item2 in map(None, sequence1, sequence):
        ...

    for index in range(start, stop, step):
        ...

    n = sequence.count(item)

    for index in range(len(sequence)):
        ...

    sequence.remove(item)

    for index in range(len(sequence)-1, -1, -1):
        ...

(also note that most basic types are *immutable*, so it's not
entirely clear how things like ++ and += should work.  for more
discussion, check the archives.  this topic isn't exactly new...)

</F>

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->




More information about the Python-list mailing list