(Sponsors) Get started learning Python with DataCamp's free Intro to Python tutorial. Learn Data Science by completing interactive coding challenges and watching videos by expert instructors. Start Now!
Python chr() function
Updated on Jan 07, 2020
The chr()
function returns a single character string represented by the integer ordinal value.
Its syntax is as follows:
chr(integer) -> single character string
Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | >>>
>>> chr(65)
'A'
>>>
>>>
>>> chr(102)
'f'
>>>
>>>
>>> chr(225) # accented a
'á'
>>>
>>>
>>> chr(21325) # swastika
'卍'
>>>
>>>
>>> chr(128512) # Grinning Face
'😀'
>>>
|
Try it out:
To convert the characters back to integers use the ord() function.
Other Tutorials (Sponsors)
This site generously supported by DataCamp. DataCamp offers online interactive Python Tutorials for Data Science. Join over a million other learners and get started learning Python for data science today!
View Comments