Nico Nico - 5 months ago 70
Python Question

How to check if a string in Python is in ASCII?

I want to I check whether a string is in ASCII or not.

I am aware of

, however when I try
, I have
TypeError: ord() expected a character, but string of length 2 found
. I understood it is caused by the way I built Python (as explained in
's documentation

Is there another way to check?

def is_ascii(s):
    return all(ord(c) < 128 for c in s)