Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the opposite of python's ord() function?

I found out about Python's ord() function which returns corresponding Unicode codepoint value. But what is the opposite function, i.e. get char value by int?

Edit: I'm new to SO, and couldn't find the answer here, so decided to post in order to everyone could find it more easily, although the answer is quite obvious. Then I read this - How much research effort is expected of Stack Overflow users? and realised it was a huge mistake. Apologies. hope it will be useful in that sense.

like image 727
dkol Avatar asked Apr 23 '15 08:04

dkol


People also ask

What is the opposite of the Ord function?

The chr(i) method is the inverse of ord() function; it takes Unicode code point (which is an integer number) and returns a string.

What is ord () in Python?

The ord() function returns the number representing the unicode code of a specified character.

What is CHR () and Ord () in Python?

Python chr() and ord() Python's built-in function chr() is used for converting an Integer to a Character, while the function ord() is used to do the reverse, i.e, convert a Character to an Integer.

What does ORD () do?

The Python ord() method converts a character into its Unicode code. The ord() method takes one argument: a string containing a single Unicode character. This method returns an integer that represents that character in Unicode.


2 Answers

chr() is what you're looking for:

print chr(65) # will print "A"
like image 157
EvenLisle Avatar answered Oct 07 '22 05:10

EvenLisle


ord(c)

Given a string of length one, return an integer representing the Unicode code point of the character when the argument is a unicode object, or the value of the byte when the argument is an 8-bit string. For example, ord('a') returns the integer 97, ord(u'\u2020') returns 8224. This is the inverse of chr() for 8-bit strings and of unichr() for unicode objects. If a unicode argument is given and Python was built with UCS2 Unicode, then the character’s code point must be in the range [0..65535] inclusive; otherwise the string length is two, and a TypeError will be raised.

chr(i)

Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string 'a'. This is the inverse of ord(). The argument must be in the range [0..255], inclusive; ValueError will be raised if i is outside that range. See also unichr().

like image 13
PythonEnthusiast Avatar answered Oct 07 '22 06:10

PythonEnthusiast