Python .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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours

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

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
    • With Certificate
    • Beginner Friendly.
      24 hours