我想用python的replace()函数删除文本中的字符,但是只删除了一半
I want to delete the characters in the text using the replace() function for python, but only half of them are deleted
minutes = ("<5 Seconds").text.replace("<", "0.").replace("Seconds", "")
print(minutes)
我想要的输出:0.5
输出:<5
我该如何解决?
你可以这样做:
m = '<5 Seconds'
m = m.replace('<', '0.').replace('Seconds', '')
print(m)
0.5
minutes = ("<5 Seconds").text.replace("<", "0.").replace("Seconds", "")
print(minutes)
我想要的输出:0.5
输出:<5
我该如何解决?
你可以这样做:
m = '<5 Seconds'
m = m.replace('<', '0.').replace('Seconds', '')
print(m)
0.5