Hacking Secret Ciphers with Python

(Ann) #1
Chapter 3 – The Interactive Shell 33

We can even use the value in the spam variable to assign spam a new value:





spam = 15
spam = spam + 5
20





The assignment statement spam = spam + 5 is like saying, “the new value of the spam
variable will be the current value of spam plus five.” Remember that the variable on the left side
of the = sign will be assigned the value that the expression on the right side evaluates to. We can
keep increasing the value in spam by 5 several times:





spam = 15
spam = spam + 5
spam = spam + 5
spam = spam + 5
spam
30





Using More Than One Variable


Your programs can have as many variables as you need. For example, let’s assign different values
to two variables named eggs and fizz:





fizz = 10
eggs = 15





Now the fizz variable has 10 inside it, and eggs has 15 inside it.

Free download pdf