×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python chr() Function: Use, Syntax, and Examples

By IncludeHelp Last updated : December 07, 2024

Python chr() function

The chr() function is a library function in Python, it is used to get character value from the given ASCII code (integer value), it accepts a number (that should be an ASCII code) and returns the character.

Syntax

The following is the syntax of chr() function:

chr(number)

Parameter(s):

The following are the parameter(s):

  • number – An ASCII code (integer value) whose character value we want.

Return Value

The return type of chr() function is <class 'str'>, it returns character (string) value.

Python chr() Function: Example 1

# python code to demonstrate an example
# of chr() function

# number (ASCII code of A)
num = 65
print("character value of ", num, " is = ", chr(num))

num = 120
print("character value of ", num, " is = ", chr(num))

num = 190
print("character value of ", num, " is = ", chr(num))

Output

character value of  65  is =  A
character value of  120  is =  x
character value of  190  is =  ¾

Python chr() Function: Example 2

# chr() with out of range

print(chr(-10009010))
print(chr(65567567))

Output

Traceback (most recent call last):
  File "/home/main.py", line 3, in <module>
    print(chr(-10009010))
ValueError: chr() arg not in range(0x110000)


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.