Python provides two built-in functions, ORD and CHR, for conversion between characters and ASCII codes. For example:
>>> Print Ord ( ' A ' )
97
>>> Print CHR ( 97 )
A
Next we can start to design our case-insensitive ConversionProgramNow:
# ! /Usr/bin/ENV Python
# Coding = UTF-8
Def Ucasechar (CH ):
If Ord (CH) In Range ( 97 , 122 ):
Return CHR (ord (CH) - 32 )
Return Ch
def lcasechar (CH ):
If ord (CH) in range ( 65 , 91 ):
return CHR (ord (CH) + 32 )
return CH
DefUcase (STR ):
Return ''. Join (MAP (ucasechar, STR ))
DefLcase (STR ):
Return ''. Join (MAP (lcasechar, STR ))
PrintLcase ('ABC me ABC')
PrintUcase ('ABC me ABC')
Output result:
ABC me ABC
ABC me ABC
Python daily delicious series (total)
Python daily delicious (1)-variable exchange
Python daily delicious (2)-the art of character Traversal
Python daily delicious (3)-character conversion
Python daily delicious (4)-isinstance determines the object type
Python daily delicious (5)-ljust just Center
...