Why is there no post-pre increment operator in python

Discussion in 'Python' started by riteshtijoriwala, Jan 13, 2006.

  1. Anyone has any idea on why is there no post/pre increment operators in
    python ?
    Although the statement:
    works but does nothing
    riteshtijoriwala, Jan 13, 2006
    1. Advertisements

  2. riteshtijoriwala

    Roy Smith Guest

    Short answer: Because Guido didn't like them.

    Longer answer: Because they encourage people to write cryptic one-liners.
    There really isn't anything you can't write with them that you couldn't
    write just as well without them. It just takes another line or two of
    code. The end result may be a little longer, but it's almost always easier
    to understand.
    Well, it works in the sense that it's not a syntax error, but it doesn't
    quite do nothing. It applies the unary + operator to the value of j, then
    does it again, then throws away the result. Granted, that's probably not
    what you expected, and probably not very useful, but it's not quite
    Roy Smith, Jan 13, 2006
    1. Advertisements

  3. riteshtijoriwala

    Tim Peters Guest

    Maybe because Python doesn't aim at being a cryptic portable assembly
    language? That's my guess ;-)
    That depends on the type of j, and how it implements the __pos__()
    method. The builtin numeric types (integers, floats, complex)
    implement __pos__ to return the base-class part of `self`. That's not
    the same as doing nothing. There is no "++" operator in Python, BTW
    -- that's two applications of the unary-plus operator.
    <type 'float'>

    If you want, you can implement __pos__ in your class so that


    posts messages to comp.lang.c asking why C is so inflexible ;-).
    Tim Peters, Jan 13, 2006
  4. riteshtijoriwala

    Mike Meyer Guest

    For lots of good reasons.
    So does --j. They both parse as a value with two unary operators
    applied to it in succession: +(+(j)) and -(-(j)).

    Mike Meyer, Jan 13, 2006
  5. riteshtijoriwala

    gene tani Guest

    "+=1" and "-=1" inflate your KLOC by .001, but they always work as
    expected with integers, it's when you do augmented assignments on lists
    and tuples that shit happens

    gene tani, Jan 13, 2006
  6. riteshtijoriwala

    Peter Hansen Guest

    The reason is pretty complex, but here it is: Python is not C.

    Peter Hansen, Jan 13, 2006
  7. riteshtijoriwala

    Roy Smith Guest

    Thanks for posting that URL; I hadn't seen the list before. Skimming over
    it, none of them really seemed noteworthy until I got to "5. Mutable
    default arguments", which rather shocked me. Good stuff to know!
    Roy Smith, Jan 13, 2006
  8. riteshtijoriwala

    gene tani Guest

    here's my full FAQ / gotcha list


    pls don't hijack threads
    gene tani, Jan 13, 2006
  9. riteshtijoriwala

    Peter Hansen Guest

    Um, he didn't "hijack" it, he follow a tangent to the discussion and
    even changed the Subject line in a very appropriate manner, both of are
    completely acceptable netiquette and long-standing Usenet practices.

    (Rather like I'm doing here.)

    Peter Hansen, Jan 13, 2006
  10. this is usenet, not gene tani's web board.

    if you have trouble dealing with subthreads, get a better news reader.

    Fredrik Lundh, Jan 13, 2006
  11. riteshtijoriwala

    gene tani Guest

    Sorry, I was trying to be helpful. One thing, i think it helps to
    glance over rejected PEPs every once in a while to reinforce what's not
    gene tani, Jan 13, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.