Hacking Secret Ciphers with Python

(Ann) #1
Chapter 6 – The Caesar Cipher 81




'HELLO' not in 'hello world!'
True
'HELLO' not in 'HELLO world!'
False
'' not in 'Hello'
False
'' not in ''
False
'D' not in 'ABCDEF'
False





Expressions using the in and not in operators are handy for conditions of if statements so that
we can execute some code if a string exists inside of another string.


Also, the in keyword used in for statements is not the same as the in operator used here. They
are just typed the same.


The find() String Method


Just like the upper() method can be called on a string values, the find() method is a string
method. The find() method takes one string argument and returns the integer index of where
that string appears in the method’s string. Try typing the following into the interactive shell:





'hello'.find('e')
1
'hello'.find('o')
4
fizz = 'hello'
fizz.find('h')
0





If the string argument cannot be found, the find() method returns the integer - 1. Notice that
the find() method is case-sensitive. Try typing the following into the interactive shell:





'hello'.find('x')






  • 1



    'hello'.find('H')






  • 1







Free download pdf