How to check if a string in Python is in ASCII?
Python 3 way:
isascii = lambda s: len(s) == len(s.encode())
Since ascii characters can be encoded using only 1 byte, so any ascii characters length will be true to its size after encoded to bytes; whereas other non-ascii characters will be encoded to 2 bytes or 3 bytes accordingly which will increase their sizes.