BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python chr() function with examples

Last Updated: July 8, 2021 by Chaitanya Singh | Filed Under: Python Tutorial

The chr() function in Python accepts an integer which is a unicode code point and converts it into a string representing a character.

Python chr() function

String chr(num)

The valid range for num is 0 to 1,114,111

Returns a string representing a character whose unicode code point value is num.

Python chr() function Example

In the following example we are passing integers values in the chr() function that represents the unicode code point values and the function returns the corresponding characters (strings).

This function returns a string with length 1 which represents the character whose unicode code point value is passed in chr() function.

myString = chr(101)
print(myString)

myString2 = chr(47)
print(myString2)

myString3 = chr(1002)
print(myString3)

Output:
Python chr() function example

Python chr() function ValueError Example

As I have already mentioned that the valid range for the integers that can be passed in the chr() function is 0 to 1,114,111, if we pass the value out of this range then we get the ValueError.

# ValueError example
myString = chr(-10)
print(myString)

Output:
Python chr function value error example

Top Related Articles:

  1. Python Recursion
  2. Python ord() function with examples
  3. Python Keywords and Identifiers with examples
  4. Python Constructors – default and parameterized
  5. Python Function Arguments – Default, Keyword and Arbitrary

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. S k jha says

    March 27, 2020 at 2:55 AM

    In chr function if I input 111411 which is within the range, in that case why it gives error

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap