Q:

How to check if price contains "-" in python

Hey guys i am trying to solve this problem, i have searched on stackoverflow but didn't find the correct answer,  so i have price and it contains

$250.88 - $650.86

or 

$650.86

i want to find if the given price has - in it then condition become true and remove the $250.88 - and only print

680.86

here is the code i wrote but it is not working :
price = '$250 - $650.86'
if (price[price.rfind('-'):]):
    val  = price[price.rfind('-'):]
    trim = re.compile(r'[^\d.,]+')
    price2 = trim.sub('', val)
else:
    price2 = trim.sub('', price)
print(price2)

A:

You can do it more simple by using split, like below:
>>> price = '$250 - $650.86'
>>> s = price.split('-')
>>> price2 = s[0].strip() if len(s) == 1 else s[1].strip()
>>> print(price2)
$650.86

Hope it helps.

