Foundations of Python

You are currently auditing this course.
74 / 134

Updating Variables

When it comes to updating the existing variable, we need to re-assign it after updating its value,

a = a + 1

It gets the current value of a, adds 1, and then updates a with the new value.

If we try to increase or decrease the value of a variable that is not yet assigned any value i.e. it doesn't exist, you get an error, because Python evaluates the right side before it assigns a value to a.

Therefore, before increasing or decreasing the value, we need to initialize the variable,

a = 0
a = a + 1
a = a - 1
a = a * 2
a = a // 3
INSTRUCTIONS

Try updating a random variable which hasn't been initialized and observe the error.


No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...