How to remove a middle character from string by strip in python?

I want remove the "+" sign from the input 'x+y' where x and y is an string(single digit) and print the result.

For example, I am entering 5+7 it should display 57

Here is the code:

opr = input("Enter string").strip("+")
print(opr)

This code is not removing the "+" sign please help!

2 answers

  • answered 2017-10-11 10:10 chakri

    You can use replace

    opr = input("Enter string").replace("+","")
    print(opr)
    

  • answered 2017-10-11 10:10 bruno desthuilliers

    If your read the FineManual(tm), you'll find out that str.strip() only removes from the start and end of the string.

    The solution here is of course to use str.replace("+", "")