I want to add one point: in Python, when we use id() function, is operator, == operator, etc, the real target we're working with is value, not variable.
a is b equals to id(a) == id(b).
In your code, inf = float('inf') will produce a value named inf.
inf is also an expression, which will be evaluated to a value.
inf is inf will be True, because the evaluated values of two expressions are same one, in fact.
In Python, focusing on values is better and easier.
For example, in CPython implementation:
a = 1
b = 1
a is b # will be true
a = 10000
b = 10000
a is b # will be false
a = '10000'
b = '10000'
a is b # will be true
If we focus on variable, such thing is weird. If we focus on values, and if I tell you that CPython implementation has cache pool, which is used for small int and some literal str value, such thing is simple again:
Because of cache pool, small int 1 is cached, str '10000' is cached too, but big int 10000 is not cached so it will be created two times.
Try to focus on values.