.isascii()

utkarsh1329's avatar
Published Sep 22, 2023
Contribute to Docs

The .isascii() string method checks whether all characters in a string are ASCII characters. It returns True if all characters in the string are within the ASCII character set, and False otherwise.

Syntax

string.isascii()

The .isascii() method in Python does not take any arguments.

Example

The .isascii() method is called on each of these strings to determine whether they consist solely of ASCII characters. This method returns True if all characters in the string are ASCII characters and False if there are any non-ASCII characters present.

check_str_A = "This is an ASCII string"
check_str_B = "This contains non ASCII characters こんにちは"
print("A: ", check_str_A.isascii())
print("B: ", check_str_B.isascii())

The output will look like this:

A: True
B: False

All contributors

Contribute to Docs

Learn Python on Codecademy