Expanding on pogo's answer, which is correct...
What surprised me (and apparently many others) is that the cluster of strings in the if mode in ...:
line is not a syntax error.
if mode in "encrypt" 'e' 'decrypt' 'd'.split():
Those strings are all compile-time constants, so string literal concatenation glues them into one string before execution starts:
>>> "encrypt" 'e' 'decrypt' 'd'
'encryptedecryptd'
The split()
method is then called on that string, which by chance does not contain any whitespace. The return value is a list containing a single string:
>>> "encrypt" 'e' 'decrypt' 'd'.split()
['encryptedecryptd']
The in
operator won't complain about being given a string (mode
) and a list of strings, but it will return False
for every value of mode
except one... which no one is ever likely to type:
>>> 'encrypt' in ['encryptedecryptd']
False
>>> 'encryptedecryptd' in ['encryptedecryptd']
True