.isascii()

utkarsh13291 total contribution
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: TrueB: False
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.