Python 3 reference · String Methods

Python String isascii() Method

Return True if the string is empty or every character is ASCII (code points 0–127).

Python 3 Since 3.7

Syntax

str.isascii()

Return value

True or False.

Examples

ASCII or notTry it yourself
print("hello".isascii(), "héllo".isascii(), "".isascii())

Output

True False True
Find non-ASCII wordsTry it yourself
words = ["cafe", "café", "naive", "naïve"]
print([w for w in words if not w.isascii()])

Output

['café', 'naïve']

Version history

VersionChange
Python 3.7Added