Home How can I represent an infinite number in Python?
Reply: 0

How can I represent an infinite number in Python?

user7891
1#
user7891 Published in September 19, 2018, 6:42 pm

How can I represent an infinite number in python? No matter which number you enter in the program, no number should be greater than this representation of infinity.

share|improve this question
  • 30
    use float('inf') – JBernardo Oct 15 '11 at 23:10
  • Is there any chance that the number will be an integer? – Mark Ransom Jul 9 '15 at 4:49
  • 14
    math.inf is useful as an initial value in optimisation problems, because it works correctly with min, eg. min(5, math.inf) == 5. For example, in shortest path algorithms, you can set unknown distances to math.inf without needing to special case None or assume an upper bound 9999999. Similarly, you can use -math.inf as a starting value for maximisation problems. – Colonel Panic Oct 12 '16 at 10:59

9 Answers 9

active oldest votes
up vote 458 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.694917 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO