Hacking Secret Ciphers with Python

(Ann) #1

34 http://inventwithpython.com/hacking


Email questions to the author: [email protected]


Figure 3 - 6. The “fizz” and “eggs” variables have values stored in them.

Let’s try assigning a new value to the spam variable. Enter spam = fizz + eggs into the
shell, then enter spam into the shell to see the new value of spam. Type the following into the
interactive shell:





fizz = 10
eggs = 15
spam = fizz + eggs
spam
25





The value in spam is now 25 because when we add fizz and eggs we are adding the values
stored inside fizz and eggs.


Variable Names


The computer doesn’t care what you name your variables, but you should. Giving variables
names that reflect what type of data they contain makes it easier to understand what a program
does. Instead of name, we could have called this variable abrahamLincoln or monkey. The
computer will run the program the same (as long as you consistently use abrahamLincoln or
monkey).


Variable names (as well as everything else in Python) are case-sensitive. Case-sensitive means
the same variable name in a different case is considered to be an entirely separate variable. So
spam, SPAM, Spam, and sPAM are considered to be four different variables in Python. They
each can contain their own separate values.

Free download pdf