Menu Close

Python chr() Function

In this tutorial, we are going to learn all about the python chr() function to get the character of the specified Unicode.
In the previous python tutorial, we have seen a python callable function to check whether an object is callable or not.

Python chr() function

Python chr function is a built-in function that is used to return the character of specified unicode. It take the unicode and return their character.

Syntax

The syntax of chr function in python is:-

chr(number)

Parameter

chr function in python accepts one parameter that is number.

  • number:- An integer represent the unicode character.

Return Value

Return value of chr function in python is character of unicode.

Python chr() function examples

Here we will use python chr() function to find the character of unicode.

Example 1:

#Get the character of 98.
x = chr(98)
print(x)

Output will be:- b

Example 2:

#Get the character of 50.
y = chr(50)
print(y))

Output will be:- 2

Example 3:

#get the character of 65.
y = chr(65)
print(y)

Output will be:- A

Integer passed chr() function is out of range().

When you passed integer out of range in chr() function, The you will get ValueError.

Example:

y = chr(-2)
print(y)

Output

Traceback (most recent call last):
  File "C:\Users\Vishvajit\Desktop\PF Article\Python Basic part1\test.py", line 1, in <module>
    y = chr(-2)
ValueError: chr() arg not in range(0x110000)

Conclusion

In this tutorial, you have learned all about Python chr() function to get the character of specified object. This is the best python built-in function to get the character of unicode character.

Other Python built-in functions

For more information:- Click Here

Previous Article
Next Article

Was this post helpful?

Related Posts

Leave a Reply