Say you’re sending customer names from a Chicago shop to a label printer that only takes ASCII. To check if a string is ASCII in Python before it goes out, call name.isascii(). It returns True only if every character is ASCII (0-127).
In this tutorial, we’ll walk through four ways to check if a string is ASCII in Python, then pin down the exact characters that fail. I ran everything on Python 3.12.5.
The sample customer names we’ll check for ASCII
Every example imports this list from orders.py:
# Customer names from a Chicago shop's 2026 order export
names = ["Emily Carter", "José Ramírez", "Ava’s Bakery",
"Order #1042 $19.99", "", "Ryan\tMitchell"]
Two names have accents, one has a curly apostrophe from Word, one is empty, one hides a tab.
Method 1: Check for ASCII with str.isascii() (Recommended)
On Python 3.7+, this built-in is the fastest option. Here’s the code on our six names:
from orders import names
for name in names:
print(f"{name!r:24} isascii: {name.isascii()}")
Output:
'Emily Carter' isascii: True
'José Ramírez' isascii: False
'Ava’s Bakery' isascii: False
'Order #1042 $19.99' isascii: True
'' isascii: True
'Ryan\tMitchell' isascii: True

How does this code work?
isascii() stops at the first character above 127. “Ava’s Bakery” fails on the curly ’, not the straight ' key.
Don’t confuse it with the built-in Python ascii() function, which escapes text instead of testing it.
Method 2: Check for ASCII with encode() and UnicodeEncodeError
This older way still earns its spot: the exception tells you where the first bad character sits. Same six strings:
from orders import names
def is_ascii(text):
try:
text.encode("ascii")
except UnicodeEncodeError as err:
bad = text[err.start]
print(f"{text!r}: {bad!r} at index {err.start}")
return False
return True
print([is_ascii(n) for n in names])
Output:
'José Ramírez': 'é' at index 3
'Ava’s Bakery': '’' at index 3
[True, False, False, True, True, True]

How does this code work?
encode("ascii") raises UnicodeEncodeError on the first unmappable character, and err.start is its index.
It’s slower on long text, since it builds bytes. Encoding anyway? See converting a string to UTF-8 in Python.
Method 3: Find the non-ASCII characters with ord()
Need every offender, not just a yes or no? Loop with ord(). Same list again:
from orders import names
for name in names:
bad = [(ch, ord(ch)) for ch in name if ord(ch) > 127]
ok = all(ord(ch) < 128 for ch in name)
print(f"{name!r:24} {ok!s:5} {bad}")
Output:
'Emily Carter' True []
'José Ramírez' False [('é', 233), ('í', 237)]
'Ava’s Bakery' False [('’', 8217)]
'Order #1042 $19.99' True []
'' True []
'Ryan\tMitchell' True []

How does this code work?
Python ord() returns a code point. all() gives the True/False, and the comprehension collects each character above 127. That 8217 means text pasted from Word.
Method 4: Check a string for ASCII with a regex
A regex fits when you already validate fields with patterns; for the basics, see regular expressions in Python.
from orders import names
import re
ASCII_ONLY = re.compile(r"[\x00-\x7F]*")
for name in names:
ok = ASCII_ONLY.fullmatch(name) is not None
print(f"{name!r:24} {ok!s:5} {re.findall(r'[^\x00-\x7F]', name)}")
Output:
'Emily Carter' True []
'José Ramírez' False ['é', 'í']
'Ava’s Bakery' False ['’']
'Order #1042 $19.99' True []
'' True []
'Ryan\tMitchell' True []
![python regex check ascii string vs code VS Code output of a Python regex fullmatch on [\x00-\x7F]* checking customer names for ASCII and listing the non-ASCII characters](https://pythonguides.com/wp-content/uploads/2026/11/python-regex-check-ascii-string-vs-code.png)
How does this code work?
[\x00-\x7F] matches any ASCII character, fullmatch() needs the whole string to match, and * lets the empty string pass. The negated class in findall() returns the misfits.
Important: plain search() without ^...$ passes any string containing one ASCII character.
Which ASCII check method should you use?
| Method | Best for | Note |
|---|---|---|
s.isascii() | Fast yes/no check | Python 3.7+ |
s.encode("ascii") | First bad index | Works on older Python |
ord() loop | Listing every offender | Slowest on big text |
re.fullmatch() | Pattern validation | Anchor the pattern |
I’d use isascii() for the check and the ord() loop only for a fix-up report. To clean failing rows, remove non-ASCII characters in Python.
Things to keep in mind when checking strings for ASCII
- Empty strings pass. Use
if name and name.isascii(). - ASCII isn’t printable. Tabs and NUL pass
isascii(); pair it withisprintable(). - Curly quotes fail. Replace
’with'first.
Working with text encodings a lot? These guides pair well with this one:
- Convert a string to ASCII in Python
- Remove Unicode characters in Python
- Python chr() function
- Check if a string is Base64 encoded in Python
Frequently asked questions
How do I check if a string is ASCII in Python?
Call s.isascii(). It’s True when every code point is 127 or lower.
Which Python version added str.isascii()?
Python 3.7. Before that, catch UnicodeEncodeError from encode().
Does isascii() return True for an empty string?
Yes. "".isascii() is True, so test blanks separately.
How do I find which characters are not ASCII?
Use [c for c in s if ord(c) > 127] or re.findall(r"[^\x00-\x7F]", s).
Can I check bytes for ASCII?
Yes. bytes.isascii() is True when every byte is 0x7F or lower.
Where is str.isascii() documented?
See str.isascii() in the Python docs.

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn