Gimme a L
'L'
Gimme a o
'o'
Gimme a s
's'
Gimme a e
'e'
The middle character is: d
The middle character is: r
The middle character is: a

What these programs demonstrate is that strings are similar to lists in several ways. The shout procedure shows that for loops can be used with strings just as they can be used with lists. The middle procedure shows that that strings can also use the len function and array indexes and slices. Most list features work on strings as well.

This works because the computer represents the characters of a string as numbers from 0 to 255. Python has a function called ord (short for ordinal) that returns a character as a number. There is also a corresponding function called chr that converts a number into a character. With this in mind the program should start to be clear. The first detail is the line: if 'a' <= character <= 'z': which checks to see if a letter is lower case. If it is than the next lines are used. First it is converted into a location so that a=0,b=1,c=2 and so on with the line: location = ord(character) - ord('a'). Next the new value is found with new_ascii = location + ord('A'). This value is converted back to a character that is now upper case.

If you haven't guessed already the function repr can convert a integer to a string and the function int can convert a string to an integer. The function float can convert a string to a float. The repr function returns a printable representation of something. Here are some examples of this:

The int function tries to convert a string (or a float) into a integer. There is also a similar function called float that will convert a integer or a string into a float. Another function that Python has is the eval function. The eval function takes a string and returns data of the type that python thinks it found. For example: