The isascii()
method is a string method in Python that checks whether all the characters in a string are ASCII characters or not. It returns True
if all the characters are ASCII, otherwise returns False
.
Parameter Values
This function does not accept any parameters.Return Values
The isascii()
method returns a bool
value: True
or False
.
How to Use isascii()
in Python
Example 1:
The isascii()
method returns True if all the characters in a string are ASCII characters, otherwise it returns False.
str1 = 'Hello123'
print(str1.isascii()) # Output: True
Example 2:
If the string contains any non-ASCII characters, the method returns False.
str2 = 'Héllo'
print(str2.isascii()) # Output: False
Example 3:
The method also returns True for an empty string, as there are no characters to check.
str3 = ''
print(str3.isascii()) # Output: True