程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python float (inf ) and float (inf)

編輯:Python
float('inf') # Set an infinite maximum 
float('-inf') # Set an infinite minimum 

Commonly used The comparison .
for example , Calculate the cost of path routing when traversing the tree .
Found in the list of options “ The cost is the lowest ” The path of :

lowest_path_cost = float('inf') # Set a maximum 
path_costs = [1, 100, 2000000000000, 50]
for path in path_costs:
if path < lowest_path_cost:
lowest_path_cost = path
lowest_path_cost # Find the value with the lowest path cost 
1

If you don't float(‘Inf’) You can use , What value would you use as the initial lowest_path_cost?

Of course, it is also possible to set some values randomly ,float(‘Inf’) Eliminate this uncertainty .

contrary float(‘-Inf’) It's the same. There are no examples here .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved