.isascii()
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
Contribute to Docs
- 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.
Learn Python on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours