Python Fundamentals - Exercises

Check Your Understanding

What values do the variables mass and age have after each of the following statements? Test your answer by executing the lines.

mass = 47.5
  age = 122
  mass = mass * 2.0
  age = age - 20
  

Solution

`mass` holds a value of 47.5, `age` does not exist
  `mass` still holds a value of 47.5, `age` holds a value of 122
  `mass` now has a value of 95.0, `age`'s value is still 122
  `mass` still has a value of 95.0, `age` now holds 102
  

Sorting Out References

What does the following program print out?

first, second = 'Grace', 'Hopper'
  third, fourth = second, first
  print(third, fourth)
  

Solution

Hopper Grace