This aspect we will be breaking down and learning about;
- Updating variables
- Expressions
- Numbers
Updating Variables
Variables can change e.g.
status = “Watching Netflix” status = “Relaxing at the beach” print(status)
Output: Relaxing at the beach
- You can Update variables as much as you want:
TRY THIS ON YOUR TERMINAL
status = “Incomplete” status == “Compete” print(status)
status = “New data required” print (status)
Output: Complete New data required.
- You can also give variables the value of other variables. For example we can give new_status variable the value of default_option
default_option = “upload” new_status = “download”
new_staues = default_option print(new_status)
Output: upload
- You can also make it display variable twice
status = Playing football print(status)
status= Walking the dog print(status)
Output: Playing football Walking the dog
Expressions
It time to give our code expressions one of them is called a string value together with a + sign . Calling string value an expression is because output create a single value. E.g.
Print(“Followers: “+”55”)
Output: Followers: 55
- When Expression contain variables, they use the value in the variables, which wee can see when adding “Follower:” to followers
followers = “55” print(“Followers:” + followers)
Output: Followers: 55
- Since expressions become value, we can store them in variables the same way as the values. e.g.
label = “Posts:” + “13” print(label)
Output: Posts: 13
Numbers
As you learnt earlier variables can also be stored in numbers, Unlike strings, numeric values don’t use quotes ” “. e.g.
active_users = 5 (without quotes)
- Numbers make it easier to keep track of numeric data. Expression can also be created with numbers too, and also use variables with numbers for calculations too. e.g.
number_of_application = 5 + 1 print(number_of_application)
Output: 6
- As we know in Operators we use *,+,/, etc. We can also turn a decimal into percentage by multiplying by 100. e.g.
percent = 0.5 * 100 print(percent)
Output: 50.0
TRY THIS IN YOUR TERMINAL
number_of_steps = 70 print(“You’re on step:”) print(number_of_steps: + 1)
Output: You’re on step: 71
- Since expressions become values, we can store calculation results in variables. e.g.
private = 3 public = 10 total = private + public print(“Total posts:”) print(total)
Output: Total posts: 13