Python built-in functions (10) -- chr, python built-in function chr

Source: Internet
Author: User

Python built-in functions (10) -- chr, python built-in function chr

English document:

chr( I)
Return the string representing a character whose Unicode code point is the integer I. For example, chr(97)Returns the string 'a', While chr(8364)Returns the string '€'. This is the inverse ord().
The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16 ). ValueErrorWill be raised if IIs outside that range
Note:
1. The function returns the string representation of the Unicode Character corresponding to the integer parameter value.
>>> Chr (97) # The parameter type is an integer 'A'> chr ('97 ') # The Traceback (most recent call last) error is returned when the parameter is input ): file "<pyshell #6>", line 1, in <module> chr ('97 ') TypeError: an integer is required (got type str) >>> type (chr (97) # The return type is a string <class 'str'>

2. Its functions are just the opposite of the ord functions.

>>> chr(97)'a'>>> ord('a')97

3. The value range of the input parameter must be 0-1114111 (0x10FFFF in hexadecimal format). OtherwiseValueError

>>> Chr (-1) # Traceback (most recent call last): File "<pyshell #10>", line 1, in <module> chr (-1) ValueError: chr () arg not in range (0x110000) >>> chr (1114111) '\ u0010ffff' >>> chr (1114112) # Traceback (most recent call last): File "<pyshell #13>", line 1, in <module> chr (1114112) ValueError: chr () arg not in range (0x110000)

 

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.