Logo
/
Programming
/
Python Course
/

Changing variables

Python: Changing variables

The word “variable” itself suggests that it can be changed. And indeed, the values of variables can change over time within the program.

For example:

# greeting
greeting = "Father!"
print(greeting)  # => Father!

greeting = "Mother!"
print(greeting)  # => Mother!

The name remained the same, but there were different data inside. Note that variables in Python require no special declaration. Instead, a variable is declared when it is first used in a program.

Variables are a powerful yet risky thing. You can't be sure right away what'll be inside it - first you have to analyze the code that comes before the variable. This is what developers do during debugging, when they try to figure out why the program doesn't work as intended.

Instructions

The status of an order is updated as it moves along. At first the order is "in transit", then it changes to "delivered".

The exercise defines a variable delivery_status with the value "in transit". Reassign its value to "delivered" and print it to the screen.

An example of reassigning a variable:

some_var = "old value"
some_var = "new value"
print(some_var)  # => new value

If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:

  • Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Found a bug? Have something to add? Pull requests are welcome!