【发布时间】:2020-05-29 15:35:47
【问题描述】:
我正在尝试删除字符串中的任何数字。
但是,当我运行我的程序时,数字被删除了,但字符串的其他部分也被删除了。
string = 'My name is Anish, & I am 22 years old! The wall is blue, and the floor is orange. The weather is great, but it is raining?'
def num_remover(words):
t = words.split()
d = [e for e in t if e.isalpha()]
a = " ".join(d)
return a
print(bluh_remover(string))
输出:
我的名字是我 22 岁 墙是,地板是 天气是,但它是
【问题讨论】:
-
添加信息是哪种编程语言会很好,也可以添加到标签中。
-
欢迎来到 SO!轻微的挑剔,但
bluh_remover不在代码中——您可能是指num_remover。你能展示你的实际输出与你的预期输出对比吗?谢谢。
标签: string list function numeric word