Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of python2 chr(int) in python3

Tags:

# python2
print(chr(174))
?

# python3
print(chr(174))
®

I'm looking for the equivalent of chr() from python2. I believe this is due to python 3 returning unicode characters rather than ASCII.

like image 999
Sam Liddle Avatar asked Feb 24 '18 00:02

Sam Liddle


1 Answers

Actually, in Py3 chr is equivalent of unichr in Py2. You can use bytes or bytearray.

For example:

>>> print(bytes([174]))
b'\xae'

or

>>> print(bytearray([174]))
bytearray(b'\xae')

b'\xae' equals to ?

like image 199
Little Roys Avatar answered Sep 23 '22 13:09

Little Roys