Hacking Secret Ciphers with Python

(Ann) #1
Chapter 5 – The Reverse Cipher 61







Remember that for the “less than or equal to” and “greater than or equal to” operators, the < or >
sign always comes before the = sign.


Type in some expressions that use the == (equal to) and != (not equal to) operators into the shell
to see how they work:





10 == 10
True
10 == 11
False
11 == 10
False
10 != 10
False
10 != 11
True
'Hello' == 'Hello'
True
'Hello' == 'Goodbye'
False
'Hello' == 'HELLO'
False
'Goodbye' != 'Hello'
True





Notice the difference between the assignment operator (=) and the “equal to” comparison
operator (==). The equal (=) sign is used to assign a value to a variable, and the equal to (==)
sign is used in expressions to see whether two values are the same. If you’re asking Python if two
things are equal, use ==. If you are telling Python to set a variable to a value, use =.


String and integer values will always be not-equal to each other. For example, try entering the
following into the interactive shell:





42 == 'Hello'
False
42 == '42'
False
10 == 10.0
True




Free download pdf