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
print("hello".isascii(), "héllo".isascii(), "".isascii())
Output
True False True
words = ["cafe", "café", "naive", "naïve"]
print([w for w in words if not w.isascii()])
Output
['café', 'naïve']
Version history
| Version | Change |
|---|---|
| Python 3.7 | Added |
Related
str.isalpha()· Return True if every character is a letter (in any alphabet) and the string isn't empty. Spaces and digits return False.str.encode()· Encode the string into bytes using a text encoding such as UTF-8 (the default), for files, networks and hashing.- Python Strings · tutorial