Python doesn't support ++, but you can do:
number += 1
Answer from Daniel Stutzbach on Stack Overflowsyntax - Python integer incrementing with ++ - Stack Overflow
How can I increment i with an additional value within a for loop?
Increment, decrement... Can we have inc(), dec() functions in Python? feature request :) - Ideas - Discussions on Python.org
Best way to increment of 1 in python?
Videos
Python doesn't support ++, but you can do:
number += 1
Simply put, the ++ and -- operators don't exist in Python because they wouldn't be operators, they would have to be statements. All namespace modification in Python is a statement, for simplicity and consistency. That's one of the design decisions. And because integers are immutable, the only way to 'change' a variable is by reassigning it.
Fortunately we have wonderful tools for the use-cases of ++ and -- in other languages, like enumerate() and itertools.count().
for i in range(4): print(i) i += 1
How can I make this print:
0
2
I search for better function to increment a number of 1
So far I have found the following suggestions:
# recursive abacus
def inc(x,n=0): return inc(x^(1<<n),inc(0,n)) if x&(1<<n) else x|x^(1<<n)
# there are 10 type of coders ...
lambda i: i++ (lambda j: j()**j())(type(i)) #halike
# dyslexia
lambda i: (sum(range(x))*2)/x # decrement #halike
# it's all about the context
lambda i: 2*i-(sum(range(i))*2)/i # banermatt
# mapreducing
lambda i: __import__('functools').partial(i.__add__, 1)() #halike
# identity crisis
lambda i: i+(i is i) # SFJulie1 (kind of) #halike
# be real
lambda i: int((x-1j**2).real) #halike
# TIMTOWTDI
lambda i: int(__import__("os").popen("perl -e'++($a=%d)&&print$a'"%i).read()) # SFJulie1
# Delegation aka someone may know the answer by SciK
lambda i: int(__import__("os").popen("perl -e'use Inline C=>q[int incr(int i){return i-~0^0;}];print incr %d'" % i).read())
#
lambda i: int((lambda x: x('subprocess').check_output([x('sys').executable, '-c', 'print %d++1'%i])))(__import__) #halike
# inchworm on a stick
lambda i:-~i # Brian
# regexp is a turing complete machine
lambda i: len(__import__('re').sub('(.)$', '\\1\\1', '1'*i)) #lost-theory (does not work on 0)
#tempis fugit
lambda i: i-(lambda t: int(t.time()-(t.sleep(1),t.time())[1]))(__import__('time'))
# being partial by willm
lambda i:__import__('itertools').dropwhile(lambda m:m==i, __import__('itertools').count(i)).next()
# pushing to the max
lambda i: next(j for j in range(__import__('sys').maxint) if j > i) # nivertius
#might work by flowblok
lambda i: i+int(round(__import__('random').random()))
# the choice of a GNU generation by sonwell
lambda i: ((lambda rec, i, A, n: rec(rec, i, A, n))(lambda rec, i, A, n: A if i == 0 else i + abs(i - ((i > -1) - (i < 0)) * rec(rec, abs(i) - 1, A * n, n + 1) / abs(i)), i, 1, 2))
#nothing compares to U by cecedille1 (and sinnead O'connors)
lambda u:cmp(u,0) * len(xrange(-1 , i, cmp(u,0) ) ) if u else 1
# it's a kind of magic by ceceddile1
lambda i:(1).__radd__(i)
# the neighbour of the beast by fabzter & samus_
addition = lambda i: int((str(i)[:-1] + {'0': '1', '1': '2', '2': '3', '3': '4', '4': '5', '5': '6', '6': '7', '7': '8', '8': '9'}[str(i)[-1]] if str(i)[-1] in {'0': '1', '1': '2', '2': '3', '3': '4', '4': '5', '5': '6', '6': '7', '7': '8', '8': '9'} else str(addition(int(str(i)[:-1])) if str(i)[:-1] else '1') + '0') if str(i) else '1')
# cloud computing by hhh333
lambda n:float(__import__('re').findall("%d.?\d* \+ 1 = (\d+\.?\d*)"%n,__import__('requests').get("http://google.com/search", params=dict(q="%f+1"%n)).text)[0])
# In the face of ambiguity, refuse the temptation to guess. by gtr053
lambda x:float(raw_input("Pretty please enter the result of %f + 1: "%x))
# pseudomenon : defeats the truth swapping trick True,False=False,True
lambda x: x+(True if True else False)
# polyglot by Book mod SFJulie1
q = 0 or """ #=;$A=41;sub A { ~-$A+2}; q' """
A=lambda A: -~A #';
print A(41) # python + perl = <3
# se(ct|x)ually amibuous by Brian
lambda i: __import__('bisect').bisect(xrange(__import__('sys').maxint), i)Are there even better way to do it?
EDIT: I will soon stop maintaining the page of the solutions.
Soz for pinpinbo solution that did not fit (polyglot is the «fait du prince») and brian core to the metal solution is nice, too.
I really thank everyone, because on one hand I never thought it would have a positive score, and on the other hand I never thought these kind of games were in fact non only fun, but also interesting: Brian & pinpinbo deserve a special mention on how easy it is to bind with C and fortran in python.
For the future I was thinking of hosting it somewhere on a blog ...