faqts : Computers : Programming : Languages : Python : Language and Syntax

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 8 people (75%) answered Yes
Recently 3 of 5 people (60%) answered Yes

Entry

Why are there no operators equivalent to C's , --, =, etc.?

Nov 11th, 2000 10:21
Dave Brueck, unknown unknown, Fredrik Lundh, Peter Schneider-Kamp, Michael Hudson


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.

Michael Hudson wrote a patch for the +=, -=, *=, /= and some other
of these operators.

A patch can be found at:

http://starship.python.net/crew/mwh/aug-patch.html
http://www-jcsu.jesus.cam.ac.uk/~mwh21/aug-patch.html

As of Python 2.0, the above operators are officially part of the 
language.