Why doesn't it keep incrementing every time I run the block?

Question:

I’m an absolute beginner, and I don’t understand why a is not incremented every time I run the code. It always prints a = 0 and a = 1.

a = 0
b = 2

print ("a = {}".format(a))

a = a + 1

print ("a = {}".format(a))

Output

I’m working on Google Colab. Thanks in advance!

EDIT: I just noticed if I keep the two first lines on a separate block like this, the code does increment. Why??

Answers:

Use two separate cells, one for declaring the variables and one for incrementing:

colab-example

Answered By: Sash Sinha
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.