Python Integer – Incrementing an Integer

In this post we’ll be creating a script that will increment an integer by 1 using the ‘+=’ operator. See the below as a very simple example.

number = 1

while True:
    number += 1
    print(number)

The example above declares an int named ‘number’ and sets its initial value to ‘1’. We than have a while loop that increment our ‘number’ int by one and then print it to output, this results in an incrementing number being sent to output. For example.

2
3
4
5
6
7
8
9
10
11
12
13
...
>>>

Leave a Reply