Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

Output

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:

colab-example

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading