def isascii(text):
 try:
  text.encode(u'ascii')
 except UnicodeEncodeError:
  return False
 return True

def isascii ( text ) : try : text . encode ( u'ascii' ) except UnicodeEncodeError : return False return True
test if text contains only ascii characters .