Python daily delicious (3)-character conversion

Source: Internet
Author: User
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

...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.