# variables.py # # Establishing a variale name with a value associated with the name message = "What's up?" print message # Updating the value of the variable with a new value message = "What's down?" print message # Establishing a name with a value initially and then updating the value # as you compute in your program is a pattern we use a lot, specially in # Python. So, remember this pattern. # The variable message here happens to have a string value at this point, # but you can even assign an integer as its value at this point in the # program like this: message = 234 print message # But, it is usually not a good idea (not a good programming style) to mix # different types of values for a given variable unless it is logically # necessary to do so in your program. # Programs are much easier to understand if you keep the variables with # values of the same type throughtout the lifetime of the variables. # In other languages such as Java changing the type of a variable like this # in mid-stream is not even allowed. # Here are some more variables with some values assigned. n = 22 print n n = 23 print n pi = 3.14159 print pi # We already know how to get the types. Let's try them again here. print type (message) message = "back to string again" print type (message) print type (n) print type (pi) # We can try some boolean variables, i.e., the variables with boolean # values (aka logical values, namely, True or False). For example, larger = (45 > 10) print larger larger = (45 < 10) print larger same = (34 == 34) print same print type(same) # You will find variables useful as you write more complex programs.