Search code examples
pythontextreplaceprintingoutput

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)

The output i wanted: 0.5

output: <5

how can I fix it?


Solution

  • You can do like this:

    m = '<5 Seconds'
    m = m.replace('<', '0.').replace('Seconds', '')
    print(m)
    
    0.5