xxxxxxxxxx
>>> 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
xxxxxxxxxx
positive_infinity = float('inf')
negative_infinity = float('-inf')
# Checking if a value is infinity
x = 10
if x == positive_infinity:
print("x is positive infinity")
elif x == negative_infinity:
print("x is negative infinity")
else:
print("x is not infinity")
# Mathematical operations with infinity
y = 5
# Adding infinity to a finite value
result = positive_infinity + y
print(result) # Output: inf
# Subtracting infinity from a finite value
result = negative_infinity - y
print(result) # Output: -inf
# Comparing two infinity values
if positive_infinity > negative_infinity:
print("Positive infinity is greater than negative infinity")
xxxxxxxxxx
# Assigning infinity to a variable
my_infinity = float('inf')
# Printing the value of infinity
print(my_infinity)
# Performing operations with infinity
print(my_infinity + 10) # Output: inf
print(my_infinity * 2) # Output: inf
print(my_infinity / 2) # Output: inf
# Comparing infinity with other numbers
print(my_infinity > 100) # Output: True
print(my_infinity < 0) # Output: False