How can I extract numbers from a string in Python?

I have a string with some numbers embedded in it, and I want to extract those numbers as separate values in Python. The numbers can be integers or floats, and they may be positive or negative. What is the best way to achieve this?

Here’s an example string:

my_string = “The price of the product is $100.50, but with a discount of 20%, it becomes $80.40.”

I want to extract the numbers 100.50, 20, and 80.40 from this string.

Here’s the code I’m currently using:

This code works for the example string, but I’m not sure if it’s the best approach or if it will work for all cases. Is there a better way to extract numbers from a string in Python?

Any suggestions or help would be appreciated. Thank you!