In this tutorial, we will use an example to show you how to remove non-ascii characters from python string.
It is similar to remove unicode characters in python string.
Python String: Remove Unicode Characters From String
1.Prepare a python string that contains non-ascii characters
string_nonASCII = " àa fuünny charactersß. "
2.Remove non-ascii characters using string..encode()
string_encode = string_nonASCII.encode("ascii", "ignore") string_decode = string_encode.decode() print(string_decode)
Run this code, you will see this ascii characters:
a funny characters