Check If a String Is Pure ASCII

Easy ⏱ 8 min 78% acceptance ★★★★☆ 4.2
Write is_ascii(s) that returns True if every character in s has an ASCII code point (0-127), and False if any character (like an accented letter or emoji) falls outside that range.

Examples

Example 1
Input
s = 'Hello123'
Output
True
Explanation

All characters are basic ASCII letters and digits.

Example 2
Input
s = 'héllo'
Output
False
Explanation

'é' has code point 233, above the ASCII range.

Constraints

  • 0 <= len(s) <= 10^4

Topics

StringsEncoding Basics

Companies

IntelServiceNow

Hints

Hint 1

`ord(c) < 128` for every character `c` tells you it is ASCII.

Hint 2

Python 3.7+ also exposes `str.isascii()` directly.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.