chr () in Python


This function return the string representing a character whose Unicode code point is the integer supplied as parameter to this function. For example, chr(65) returns the string 'A', while chr(126) returns the string '~'.

Syntax

The syntax of the function is as below.

chr(n) where n is an integer value

Example

The below program shows how the chr() is used. We supply various integer values as parameter and get back the respective characters.

 Live Demo

# Printing the strings from chr() function
print(chr(84),chr(85),chr(84),chr(79),chr(82))

Running the above code gives us the following result −

T U T O R

Using a series of numbers

We can take help of python data structures like lists to loop through a series of numbers and apply char function to create a required string. In the below example we see that we have used a list to

Example

 Live Demo

str = ""
series = [84,85,84,79,82,73,65,76,83]
for i in range(0,len(series)):
   char = chr(series[i])
   str = str + char
   i=i+1
print(str)

Output

Running the above code gives us the following result −

TUTORIALS

Updated on: 23-Aug-2019

624 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements