我需要搜索一个字符串,并判断其名称中是否包含数字.如果是的话,我想什么都不做.我已经开始做类似的事情,但我没有找到解决问题的方法.
table = "table1"
if any(chr.isdigit() for chr in table) == True:
table = table.replace(chr, "_")
print(table)
# The output should be "table"
有什么 idea 吗?
我需要搜索一个字符串,并判断其名称中是否包含数字.如果是的话,我想什么都不做.我已经开始做类似的事情,但我没有找到解决问题的方法.
table = "table1"
if any(chr.isdigit() for chr in table) == True:
table = table.replace(chr, "_")
print(table)
# The output should be "table"
有什么 idea 吗?
你可以用很多不同的方法来做.下面是如何使用re模块完成的:
import re
table = 'table1'
table = re.sub('\d+', '', table)