Use Python’s built-in str.isascii() method: text.isascii() returns True when the string is empty or every character is in the ASCII range U+0000 through U+007F. It has been available since Python 3.7.
Check a string with str.isascii()
For Python 3.7 and later, call the method directly on the string:
text = "Hello, world!"
print(text.isascii()) # True
text = "café"
print(text.isascii()) # False
The method checks every character, not whether the text looks like an English word. A character outside U+0000–U+007F makes the result False. The empty string returns True, because it contains no non-ASCII characters. See the Python 3.13 documentation for str.isascii().
Use a fallback on Python versions before 3.7
str.isascii() was added in Python 3.7. If your code must run on an earlier version, try strict ASCII encoding and catch UnicodeEncodeError:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match#1 Best Overall
def is_ascii(text):
try:
text.encode("ascii")
except UnicodeEncodeError:
return False
return True
This returns True for an empty string and False if any character cannot be encoded as ASCII. Strict encoding leaves the input unchanged and makes an unencodable character an explicit error; modes such as errors="ignore" or errors="replace" can discard or alter characters, so they do not test whether the original string was entirely ASCII. Python’s Unicode HOWTO explains the distinction between Unicode strings and encoding them as bytes.
ASCII does not mean printable or alphanumeric
ASCII includes control characters as well as letters, digits, punctuation, and whitespace. Therefore, isascii() answers only whether all code points are within the ASCII range. If your requirement is that text be printable or contain only letters and digits, apply a separate check for that requirement.
Quick Recap
Best Value
Rank #2
Which approach should you use?
| Approach | Python compatibility | Best for |
|---|---|---|
text.isascii() |
Python 3.7 and later | Clear, direct checks on supported runtimes |
Strict text.encode("ascii") with UnicodeEncodeError handling |
Older Python versions | Code that must support runtimes predating Python 3.7 |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




