A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Python program to print ASCII value of a character
Q:

Python program to print ASCII value of a character

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now