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

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))


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??

>Solution :

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


Leave a Reply