Home » Python » Python programs

Python program to print ASCII value of a character

Here, we are going to learn how to print the ASCII value of a given character in Python?
Submitted by IncludeHelp, on March 30, 2019

Given a character, and we have to find its ASCII code.

ASCII value of character in Python

In python, to get an ASCII code of a character, we use ord() function. ord() accepts a character and returns the ASCII value of it.

Syntax:

    ord(character);

Example:

    Input:
    char_var = 'A'

    Function call:
    ord(char_var)

    Output:
    65

Python code to find ASCII value of a character

# python program to print ASCII
# value of a given character

# Assigning character to a variable
char_var = 'A'
# printing ASCII code
print("ASCII value of " + char_var + " is = ", ord(char_var))

char_var = 'x'
# printing ASCII code
print("ASCII value of " + char_var + " is = ", ord(char_var))

char_var = '9'
# printing ASCII code
print("ASCII value of " + char_var + " is = ", ord(char_var))

Output

ASCII value of A is =  65
ASCII value of x is =  120
ASCII value of 9 is =  57





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.