+ 1
How remove minus from string?
How to remove minus from string E.g " -50" to "50" I have output -50 but i want to show 50 so what method i can use.
8 ответов
+ 4
x.lstrip('-')
+ 4
s = '-50'
print(abs(int(s)))
n = -50
print(abs(n)
+ 3
your_string = "-50"
print(your_string[1:])
+ 3
# Hi! One way is to use replace:
>>> s = "-40"
>>> p = s.replace('-', '')
>>> print(p)
40
+ 3
MONSTER MIKE ,
this issue may be also solved in a different way.
▪︎where is this string "-50" coming from?
▪︎do you get a string that comes from an input or from a file?
▪︎or is it created by a calculation and then converted to string?
thanks!
+ 2
Hi Mike!
There are many ways to remove minus from a string.
I think using slicing method is a better option .
num = "-50"
print(num[1:])
It returns all characters from 2nd character.
+ 1
Lothar,
It created by calculation and i find solution but thank you for your time