How to remove all non-ASCII characters from a string in Python

1 Answer

0 votes
input_str = "©€ABC£µ¥xyz!® 123 こんにちは"

# Remove non-ASCII characters
filtered_str = ''.join(ch for ch in input_str if ord(ch) <= 127)

print(filtered_str)


'''
run:

ABCxyz! 123 

'''

 



answered Jun 13 by avibootz
...