Calin Paul Alexandru
Calin Paul Alexandru

Reputation: 4752

Python: ++ operator

I often require doding a simple 1 unit incrementation (++) in Python.

I never seem to find a better solution than

x = x + 1

What am I doing wrong ?

Upvotes: 7

Views: 9891

Answers (2)

Lyn Headley
Lyn Headley

Reputation: 11588

The answer you are looking for is:

x += 1

Upvotes: 5

Mark Byers
Mark Byers

Reputation: 837906

Python doesn't have a ++ operator. You should use the += operator:

x += 1

Upvotes: 20

Related Questions