Method 1:
try: value = a/b except ZeroDivisionError: value = float('Inf') orMethod 2:
if b != 0: value = a / b else: value = float('Inf') But be aware that the value could as well be -Inf, so you should make a more distinctive test. Nevertheless, this above should give you the idea how to do it.