isascii() String Method in Python with Examples

isascii() method returns True if all characters in the string are ASCII otherwise it returns False.

ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.

Example 1: isascii() String Method


message = 'welcome'

if message.isascii():
    print('"%s" is ASCII string.' %(message))
else:
    print('"%s" is not ASCII string.' %(message))

Output

"welcome" is ASCII string.

Example 2: isascii() String Method


message = 'welcome कखग' 

if message.isascii():
    print('"%s" is ASCII string.' %(message))
else:
    print('"%s" is not ASCII string.' %(message))

Output

"welcome कखग"  is  not  ASCII string.


Related String Methods