[Tutor] a function I fail to understand

Alex Hall mehgcap at gmail.com
Tue Mar 22 02:38:15 CET 2011


On 3/21/11, David <ldl08 at gmx.net> wrote:
> Hello list,
>
> I am having trouble understanding the following function. What trips me
> up is the "letter = letter.lower()" line.
>
> As I understand, the function takes a letter and assigns True to a
> letter if it is upper case.
No, the function takes a letter and returns that letter in its uppercase form.
lr="a"
lr.upper() #lr now = A
lr.lower() #lr now equals a
I should actually say that it takes a string and uppercases any
letters in it. It just happens that you are dealing with one letter
here.
>
> But then he goes to
>
> letter = letter.lower()
>
> and all letters are converted back to lower again!?? The point is that,
> to my understanding, the logic follows from the first block to
> letter = letter.lower(). Isn't that true?
>
> Thanks for helping me out,
>
> David
>
>
> def rotate13_letter(letter):
>     """
>     Return the 13-char rotation of a letter.
>     """
>     do_upper = False
>     if letter.isupper():
>         do_upper = True
>
>     letter = letter.lower()
>     if letter not in CHAR_MAP:
>         return letter
>
>     else:
>         letter = CHAR_MAP[letter]
>         if do_upper:
>             letter = letter.upper()
>
>     return letter
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap


More information about the Tutor mailing list