Find the ASCII value of each character of the string in Python

Here, we will learn how to find the ASCII value of each character of the given string in Python programming language?
Submitted by Bipin Kumar, on December 06, 2019

A string will be given by the user and we have to write Python code that prints the ASCII value of each character of the string. ASCII stands for the American Standards Code for Information Interchange. It provides us the numerical value for the representation of characters. To solve this problem, we will use the range() function and ord() function. Here, we will use simple techniques to solve this problem. Before going to solve this problem, we will learn a little bit about the range() and ord() function.

Python range() function

The range() is a built-in function available in Python. In simple terms, the range allows them to generate a series of numbers within a given interval. This function only works with the integers i.e. whole numbers.

Python ord() function

The ord() function in Python accepts a string of length 1 as an argument and returns the ASCII value of the passed argument. For example, ord('a') returns the integer 97.

Read more: ASCII – American Standard Code for Information Interchange.


# initialize a string
ascii_codes=[] # to contain ASCII codes

# getting ASCII values of each character
# using ord() method and appending them
# to "A"
for i in range(len(s)): 

# printing the result    
print('The ASCII value of each character are:',ascii_codes)


The ASCII value of each character are: [77, 111, 116, 105, 104, 97, 114, 105]

Python String Programs »



Comments and Discussions!





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

© some rights reserved.