Wednesday, October 1, 2008

Chapter 3

In Chapter 3, we will be learning to use variables. We start off with assigning values to names. Python makes it is to do so. An example of creating variables is:

first_string = "Boston"
second_string = "New York"
first_number = 2
second_number = 3
print " The first variables are %s, %s, %d, %d" % (first_string, second_string, first_number, second_number)

'The first variables are Boston, New York, 2, 3

The name in which you use doesn't relate it to the data that you are inputting. You can name it whatever way you want, but we named it in the above example in correlation what the data was. I could have named "Boston" this: first_city or first_number . This would have still given the data.

A great example of how to label for you own needs is:

lightbulbs_in_closet = 10
lightbulbs_in_lamps = 12

You can also alter the named values. It is quite simple:

lightbulbs_in_closet = 10
lightbulbs_in_closet = lightbulbs_in_closet + 4
lightbulbs_in_closet
       14

The only thing that you cannot due with naming can be found at the bottom of pg. 29. This gives you a list of words that will not work because they are built-in words that are reserved for special use to prevent any confusion.

No comments: