×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python program to find ASCII value of a character

Here, we are going to learn how to print the ASCII value of a given character in Python? By IncludeHelp Last updated : April 09, 2023

Problem statement

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

ASCII value of character in Python

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

Syntax

ord(character);

Example

Consider the below example with sample input and output:

Input:
char_var = 'A'

Function call:
ord(char_var)

Output:
65

Python program 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

Python Basic Programs »

Advertisement
Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.