Q:

Python program to print ASCII value of a character

belongs to collection: Python basic programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python basic programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python program for simple interest... >>
<< Python Arithmetic Operators Example...