Recall that variables are containers for storing information. For example,
a = "Hello, world!" print a
The = sign is an assignment operator which tells the interpreter to assign the value ‘‘Hello, world!’’ to the variable a.
a = "Hello, world!" a = "and goodbye..." print a
Taking this second example, the value of $\verb!a!$ after executing the ﬁrst line above is $\verb!‘‘Hello, world!’’!$. But, after
executing the second line, the value of $\verb!a!$ changes to ‘‘and goodbye...’’. Since we ask the program to print out
$\verb!a!$ only after the second assignment statement, that is the value that gets printed. If you wanted to save the values
of both strings, you should change the second variable to another valid variable name, such as $\verb!b!$.
Variables are useful because they can cut down on the amount of code you have to write. Write
a program that prints out the tic-tac-toe board from exercise 1.2 , but which uses variables to cut down on the
amount of typing you have to do. Hint - how many diﬀerent variables should you need?
MIT, EECS : A Gentle Introduction to Programming Using Python
Canelake, Sarina. 6.189 A Gentle Introduction to Programming Using Python, January IAP 2011. (Massachusetts Institute of Technology: MIT OpenCourseWare), http://ocw.mit.edu (Accessed 08 Mar, 2012). License: Creative Commons BY-NC-SA