Python: How to Remove Multiple Characters from a String
You can use the 'replace' method in Python to remove multiple characters from a string. Here's an example:
s = 'hello, world! 1234'
s = s.replace(',', '').replace('!', '').replace(' ', '')
print(s) # Output: helloworld1234
In this code, we first replace commas, exclamation marks, and spaces with empty strings. Then we assign the result back to the variable 's', effectively removing these characters from the string.
原文地址: https://www.cveoy.top/t/topic/mUV5 著作权归作者所有。请勿转载和采集!