【发布时间】:2023-02-05 03:13:44
【问题描述】:
我希望用户能够输入多个他们想要删除的字符。它有效,但仅当输入一个字符时。
string = input("Please enter a sentence: ")
removing_chars = input("Please enter the characters you would like to remove: ")
replacements = [(removing_chars, "")]
for char, replacement in replacements:
if char in string:
string = string.replace(char, replacement)
print(string)
【问题讨论】:
-
如果以下任一答案解决了您的问题,那么您应该将最能帮助您的答案标记为正确。这将有助于指导其他人将来遇到同样的问题。
标签: python