# chr() in Python

## chr() in Python

The chr() method returns a string representing a character whose Unicode code point is an integer.
Syntax:

```chr(num)
num : integer value
```
• The chr() method takes only one integer as argument.
• The range may vary from 0 to 1,1141,111(0x10FFFF in base 16).
• The chr() method returns a character whose unicode point is num, an integer.
• If an integer is passed that is outside the range then the method returns a ValueError.

Example: Suppose we want to print ‘G e e k s f o r G e e k s’.

 `# Python program to illustrate ` `# chr() builtin function` ` ` `print``(``chr``(``71``), ``chr``(``101``),` `chr``(``101``), ``chr``(``107``),` `chr``(``115``), ``chr``(``32``),` `chr``(``102``), ``chr``(``111``),` `chr``(``114``),``chr``(``32``),` `chr``(``71``), ``chr``(``101``),` `chr``(``101``), ``chr``(``107``), ` `chr``(``115``))`

Output:

```G e e k s   f o r   G e e k s
```

Another example :

 `# Python program to illustrate ` `# chr() builtin function` ` ` `numbers ``=` `[``17``, ``38``, ``79``]` ` ` `for` `number ``in` `numbers:` `     ` `    ``# Convert ASCII-based number to character.` `    ``letter ``=` `chr``(number)` `    ``print``(``"Character of ASCII value"``, number, ``"is "``, letter)`

Output:

```Character of ASCII value 17 is
Character of ASCII value 38 is  &
Character of ASCII value 79 is  O```

What happens if we give something out of range?

 `# Python program to illustrate ` `# chr() builtin function` `# if value given is ` `# out of range` ` ` `# Convert ASCII-based number to character` `print``(``chr``(``400``))`

Output:

```No Output
```

We wont get any output and the compiler will throw an error:

```Traceback (most recent call last):
File "/home/484c76fb455a624cc137946a244a9aa5.py", line 1, in
print(chr(400))
UnicodeEncodeError: 'ascii' codec can't encode character
'\u0190' in position 0: ordinal not in range(128)```

Last Updated on November 13, 2021 by admin

## Create a Pandas DataFrame from List of DictsCreate a Pandas DataFrame from List of Dicts

Pandas DataFrame is a 2-dimensional labeled data structure with columns of potentially different types. It

## Python – Simple GUI calculator using TkinterPython – Simple GUI calculator using Tkinter

Python | Simple GUI calculator using Tkinter Python offers multiple options for developing a GUI

## Drop rows from Pandas dataframe based on certain condition applied on a columnDrop rows from Pandas dataframe based on certain condition applied on a column

Pandas provides a rich collection of functions to perform data analysis in Python. While performing

## Vectorization in PythonVectorization in Python

Vectorization in Python We know that most of the application has to deal with a

## Python String count() MethodPython String count() Method

Python String count() Method Python String count() function is an inbuilt function in python programming language that

## Python – Which is faster to initialize lists?Python – Which is faster to initialize lists?

Python | Which is faster to initialize lists? Python is a very flexible language where

## Python – os.path.split() methodPython – os.path.split() method

Python | os.path.split() method OS module in Python provides functions for interacting with the operating system.

## Get() method for dictionaries in PythonGet() method for dictionaries in Python

Get() method for dictionaries in Python Python get() method return the value for the given key