Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

Represent infinity as an integer in Python 2.7

Asked by Anusha Acharya Apr 3, 2021 13 views 1 answer
Share

About this question

 I am wondering how to define inf and -inf as an int in Python 2.7. I tried and it seems inf and -inf only works as a float.

a = float('-inf') # works

b = float('inf') # works 

c = int('-inf') # compile error, ValueError: invalid literal for int() with base 10: 'inf' 

d = int('inf') # compile error, ValueError: invalid literal for int() with base 10: 'inf'

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.