Home » Python

chr() function with example in Python

Python chr() function: Here, we are going to learn about the chr() function in Python with example.
Submitted by IncludeHelp, on April 02, 2019

Python chr() function

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:

    chr(number)

Parameter:number – an ASCII code (integer value) whose character value we want.

Return value: str – returns character (string) value.

Example:

    Input:
    num = 65
    print(chr(num))
    
    Output:
    A

Python code to find character value from given ASCII code

# 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 =  ¾





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.