Flash Sale: Flat 70% + Addl. 25% Off on all Courses | Use Coupon DS25 in Checkout | Offer Expires In

  Enroll Now

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 update 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 updating, 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...