Home » Python

Return value of chr(ord('A')) in Python

Python example of chr() and ord() functions: Here, we are going to learn about the functions chr() and ord() functions in python.
Submitted by IncludeHelp, on March 31, 2019

1) Python ord() function

ord() function is a library function in Python, it accepts a character and returns it's ASCII value.

Example:

    print(ord('A')) //returns 65

2) Python chr() function

chr() function is a library function in Python, it accepts a value (ASCII code) and returns characters.

Example:

    print(chr(65)) //returns A

Return value of chr(ord('A'))

Statement chr(ord('A')) evaluation – ord('A') will return 65 and then chr(65) will return character value of ASCII code 65, thus, it will return 'A'.

Python code to demonstrate example of chr() and ord() functions

# python code to demonstrate example of 
# chr() and ord() function

# printing ASCII codes
c = 'A'
print("ASCII value of " + c + " is = ", ord(c))
c = 'X'
print("ASCII value of " + c + " is = ", ord(c))
c = 'a'
print("ASCII value of " + c + " is = ", ord(c))
c = 'z'
print("ASCII value of " + c + " is = ", ord(c))

# printing characters
val = 65
print("CHAR value of ", val,  " is = " + chr(val))
val = 88
print("CHAR value of ", val,  " is = " + chr(val))
val = 97
print("CHAR value of ", val,  " is = " + chr(val))
val = 122
print("CHAR value of ", val,  " is = " + chr(val))

# chr(ord('A')
print("value of the statement is: " + chr(ord('A')))

Output

ASCII value of A is =  65
ASCII value of X is =  88
ASCII value of a is =  97
ASCII value of z is =  122
CHAR value of  65  is = A
CHAR value of  88  is = X
CHAR value of  97  is = a
CHAR value of  122  is = z
value of the statement is: A





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.