Teach Your Kids To Code: A Parent-friendly Guide to Python Programming

(vip2019) #1
Conditions (What If?) 97

And you can check whether a character is a lowercase letter
with the islower() function:





'P'.islower()
False
'p'.islower()
True





A string is a collection of characters, so looping through a string
in Python with a for loop will break the string into individual char-
acters. Here, letter will loop through each character in the string
variable message:


for letter in message:


Finally, we can use the regular addition operator + (plus) to
add strings together or add letters onto a string:





'Bry' + 'son'
'Bryson'
'Payn' + 'e'
'Payne'





Here, we add the second string onto the end of the first.
Adding strings together is called appending. You may also see
string addition referred to as concatenation; just remember that’s
a fancy word for adding two or more strings together.


The Value of Character(s)


The final tool we need to build our encoder/decoder program is the
ability to perform math on individual letters, like adding 13 to the
value of the letter A to get the letter N. Python has a function or
two that can help.
Every letter, number, and symbol is turned into a number
value when stored on a computer. One of the most popular number-
ing systems is ASCII (American Standard Code for Information
Interchange). Table 5-3 shows the ASCII values of some keyboard
characters.

Free download pdf