반응형
I simply copy and paste a post that was posted on stackoverflow.
It acts as an unbounded upper value for comparison. This is useful for finding lowest values for something. for example, calculating path route costs when traversing trees.
e.g. Finding the "cheapest" path in a list of options:
>>> lowest_path_cost = float('inf')
>>> # pretend that these were calculated using some worthwhile algorithm
>>> path_costs = [1, 100, 2000000000000, 50]
>>> for path in path_costs:
... if path < lowest_path_cost:
... lowest_path_cost = path
...
>>> lowest_path_cost
1
if you didn't have float('Inf')
available to you, what value would you use for the initial lowest_path_cost
? Would 9999999
be enough -- float('Inf')
removes this guesswork.
Reference site : https://stackoverflow.com/questions/34264710/what-is-the-point-of-floatinf-in-python
반응형
'<개인공부> - IT > [Python]' 카테고리의 다른 글
Python regular expression match and search methods (0) | 2020.03.24 |
---|---|
International Morse code (di-dah) (0) | 2019.02.25 |
Regular expression practice (0) | 2019.01.17 |
Rotate Image (Rotate array values 90 degrees, clockwise) (0) | 2019.01.16 |
python count built-in function example (0) | 2019.01.15 |