Python .isascii()
Published Sep 22, 2023
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
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