如何从python中的字符串中删除这些特殊的ascii字符?

Aks*_*hay -1 python

string='I’m celebrating my sixth month anniversary of no longer being a customer of Star Wars. I’ve saved a lot of money'
Run Code Online (Sandbox Code Playgroud)

从上面的字符串我想摆脱所有的特殊字符.

blh*_*ing 5

如果您只想删除所有非ASCII字符string:

print(''.join(c for c in string if ord(c) < 128))
Run Code Online (Sandbox Code Playgroud)

这输出:

Im celebrating my sixth month anniversary of no longer being a customer of Star Wars. Ive saved a lot of money
Run Code Online (Sandbox Code Playgroud)

但是,最好找出原始字符串的编码是什么,并使用bytes.decode它将其转换为原始内容而不删除任何内容.