Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Nope, it is not possible to overload the unary ++ operator, because it is not an operator at all in Python.</p> <p>Only (a subset of) the operators that are allowed by the Python syntax (those operators that already have one or more uses in the language) may be overloaded.</p> <p><a href="http://docs.python.org/reference/lexical_analysis.html#operators" rel="nofollow noreferrer">These</a> are valid Python operators, and <a href="http://docs.python.org/library/operator.html" rel="nofollow noreferrer">this page</a> lists the methods that you can define to overload them (the ones with two leading and trailing underscores).</p> <p>Instead of i++ as commonly used in other languages, in Python one writes i += 1.</p> <p>In python the + sign needs an operand to its right. It <em>may</em> also have an operand to its left, in which case it will be interpreted as a binary instead of a unary operator. +5, ++5, ..., ++++++5 are all valid Python expressions (all evaluating to 5), as are 7 + 5, 7 ++ 5, ..., 7 ++++++++ 5 (all evaluating to 7 + (+...+5) = 12). 5+ is <em>not</em> valid Python. See also <a href="https://stackoverflow.com/questions/470139/why-does-12-3-in-python">this question</a>.</p> <p><strong>Alternative idea</strong>: Depending on what you actually wanted to use the ++ operator for, you may want to consider overloading the <a href="http://docs.python.org/reference/datamodel.html#object.__pos__" rel="nofollow noreferrer">unary (prefix) plus operator</a>. Note, thought, that this may lead to some odd looking code. Other people looking at your code would probably assume it's a no-op and be confused.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload