简体   繁体   中英

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 and it should display 57

Here is the code:

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

This code is not removing the "+" sign.

You can use replace

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

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("+", "")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM