What keywords do you use to express the "infinite" argument in Python?

Asked 2 years ago, Updated 2 years ago, 50 views

C usually gives the initial value of min to the maximum value from numeric_limits when solving the algorithm problem. That way, if(min>somval) min = someval will run correctly.

By the way, Python dynamically determines the type, and this question [Is there no limit on the minimum integer value and maximum value of Python? Looking at it, I don't think it's good to use maxint

I wonder if there is a way to express the value of infinite or maximum limit in Python.

python infinite

2022-09-22 22:12

1 Answers

To express infinity in Python

test = float("inf")

# 3.5 or higher
import math
test = math.inf

You can write. Then

returns all true. Of course, if x is "nan" or equally infinite, you can return False.

And only in python 2.x (3 is not applicable)

float('inf') < Ellipsis

returns False


2022-09-22 22:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.