You can use a list comprehension:

>>> s = 'hi'
>>> [ord(c) for c in s]
[104, 105]
Answer from Mark Byers on Stack Overflow
🌐
Python
docs.python.org › 3 › library › string.html
Common string operations — Python 3.14.4 documentation
However, in some cases it is desirable to force a type to be formatted as a string, overriding its own definition of formatting. By converting the value to a string before calling __format__(), the normal formatting logic is bypassed. Three conversion flags are currently supported: '!s' which calls str() on the value, '!r' which calls repr() and '!a' which calls ascii().
Discussions

How do I convert a list of ascii values to a string in python? - Stack Overflow
I've got a list in a Python program that contains a series of numbers, which are themselves ASCII values. How do I convert this into a "regular" string that I can echo to the screen? More on stackoverflow.com
🌐 stackoverflow.com
Converting String Into Byte Array In ASCII Presentation
I'm not entirely sure what you're trying to do here. hex() returns a string representation of a hex value, that's not what you want at all. But what are you actually planning to do with the bytearray? I suspect you just want bytearray(text.encode()) but it's hard to tell from this. More on reddit.com
🌐 r/learnpython
5
1
April 21, 2023
How do I "Convert Ascii Text to HTML Character Entities"
Why do you want to do that? If you need raw bytes you can do that in the conversion step: >>> x = ' سازمان جهان ی بهداشت' >>> x.encode('ascii', 'xmlcharrefreplace') b' سازمان جهان ی بهداشت' More on reddit.com
🌐 r/learnpython
3
1
July 6, 2021
How to take inputs from an ascii file in Python
Two comments: 1.- ascii does not imply plain txt: a json is also ascii. 2.- if your project is much bigger, as you noted, then perhaps you should prepare the data adequately, e.g. in a csv that can be directly read into a dataframe. More on reddit.com
🌐 r/learnpython
6
1
December 16, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-convert-string-list-to-ascii-values
Convert String List to ASCII Values - Python - GeeksforGeeks
January 19, 2026 - The ord() function returns the ASCII value of a character. We use a nested list comprehension to iterate through each string and convert its characters.
🌐
Delft Stack
delftstack.com › home › howto › python › convert string to ascii python
How to Convert String to ASCII Value in Python | Delft Stack
February 2, 2024 - This tutorial will explore the numerous methods available to convert a string to ASCII in Python. We can use the for loop and the ord() function to get the ASCII value of the string. The ord() function returns the Unicode of the passed string.
🌐
Vultr Docs
docs.vultr.com › python › built-in › ascii
Python ascii() - Convert Object to ASCII | Vultr Docs
September 27, 2024 - The ascii() function in Python is a built-in utility that converts any object into an ASCII string representation. This is particularly useful for rendering readable versions of objects that contain non-ASCII text, such as special characters ...
🌐
Blogger
love-python.blogspot.com › 2008 › 04 › convert-text-to-ascii-and-ascii-to-text.html
Convert text to ASCII and ASCII to text - Python code
April 29, 2008 - # program to print the list of characters and their ASCII values for value in range(0, 255): print "ASCII Value:", value, "\t", "Character:", chr(value), "\n" Here is another simple ASCII encoding-decoding program: # Convertion from text to ASCII codes message = raw_input("Enter message to encode: ") print "Decoded string (in ASCII):" for ch in message: print ord(ch), print "\n\n" # Convertion from ASCII codes to text message = raw_input("Enter ASCII codes: ") decodedMessage = "" for item in message.split(): decodedMessage += chr(int(item)) print "Decoded message:", decodedMessage Hope you got a clear understanding of how to convert between text and ASCII code.
🌐
Quora
quora.com › How-do-I-convert-ASCII-code-in-Python
How to convert ASCII code in Python - Quora
(Information reflects Python capabilities current through May 2024.) ... I have knowledge about Python Programming. · Author has 211 answers and 449.4K answer views · 4y · You can use chr() or ord() methods to convert ASCII code conversions.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › ascii-in-python
ascii() in Python - GeeksforGeeks
January 24, 2026 - Python provides the built-in ascii() function to return a printable representation of an object using only ASCII characters.
🌐
Programiz
programiz.com › python-programming › methods › built-in › ascii
Python ascii() (With Examples)
In the above example, we have used the ascii() method to replace non-printable characters with their corresponding ascii value. ... In the above example, we have used the ascii() method with a list. The method replaces the non-ascii characters ö with \xf6 and ñ with \xf1.
🌐
PyPI
pypi.org › project › art
art · PyPI
ASCII art is also known as "computer text art". It involves the smart placement of typed special characters or letters to make a visual shape that is spread over multiple lines of text. ART is a Python lib for text converting to ASCII art fancy.
      » pip install art
    
Published   Apr 12, 2025
Version   6.5
🌐
Programiz
programiz.com › python-programming › examples › ascii-character
Python Program to Find ASCII Value of Character
Your turn: Modify the code above to get characters from their corresponding ASCII values using the chr() function as shown below.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-ways-to-convert-list-of-ascii-value-to-string
Ways to Convert List of ASCII Value to String - Python - GeeksforGeeks
July 12, 2025 - For converting ASCII values to characters, a list comprehension can be used in conjunction with chr() to generate a list of characters, which is then joined into a single string using ''.join(). This approach is both efficient and Pythonic, often preferred for its readability and clarity.
🌐
Toppr
toppr.com › guides › python-guide › examples › python-examples › python-program-find-ascii-value-character
Python Program to Get ASCII value of Char Python
November 8, 2021 - Q2. How do I get the ASCII value of a character in Python 3? In Python 3, the ord () function works to obtain the ASCII value of a character. The function requires a character to be passed as its parameter.
🌐
Reddit
reddit.com › r/learnpython › converting string into byte array in ascii presentation
r/learnpython on Reddit: Converting String Into Byte Array In ASCII Presentation
April 21, 2023 -

Hello everyone!

I am trying to convert a string into a byte array. If I for example use the string 'Hello' I want to get something like this to store it in a byte array variable:

b'\x48\x45\x4C\x4C\x4F'

What I tried is following:

buf = bytearray(50) # length of text string varies, so I reserved a buffer for a max length of 50 chars

char_arr = [char for char in text]

for i in range(0, len(char_arr)):

buf[i] = hex(ord(char_arr[i]))

This could possibly be total nonsense and I feel like I am making things way too complicated. The variable "text" is the string i read from. I tried converting the string into a char array to read it into the byte array. While doing that I used hex(ord()) to convert the char into its hexadecimal ASCII representation. I just started programming in this language to use CircuitPython on my Raspberry Pi Pico. I get an error called "can't convert str to int". Any suggestions? Thanks in advance!

🌐
Portland State University
web.cecs.pdx.edu › ~lmd › cs199 › notes-week4.htm
ASCII Character set
The chr function in Python will convert a number into it’s ASCII character. ... Exercise: write your first name as a list of numbers that represent ASCII characters. ... Notice that ASCII characters each take up 7 bits. You’ll notice that the numbers range from 0 to 127.
🌐
W3Schools
w3schools.com › python › ref_func_ascii.asp
Python ascii() Function
The ascii() function returns a readable version of any object (Strings, Tuples, Lists, etc). The ascii() function will replace any non-ascii characters with escape characters: ... If you want to use W3Schools services as an educational institution, ...
🌐
Python Pool
pythonpool.com › home › blog › 3 proven ways to convert ascii to string in python
3 Proven Ways to Convert ASCII to String in Python - Python Pool
April 26, 2021 - It is a character encoding that uses numeric codes to represent characters from 0 to 127. These include upper and lowercase English letters, numbers, and punctuation symbols. For example, the ASCII code for character A is 65, and Z is 90. Here, we will be discussing all the different ways through which we can convert ASCII into string in python: