-3

Do you know that ≥90% Python tutorials of the float() function are wrong?

wyz23x2
  • 298
  • 4
  • 16

1 Answers1

-2

Yes! Many state this:

It is invalid to give strings like "abc", "Hello" to float().

No no no! Test this:
Tested on Python 3.8.2 of Windows 10 1909 64-bit Yes! There's actually ∞ and NaN in Python! But this is invalid for int() and complex().
So you can write a subclass of float to let the __truediv__ and __floordiv__ methods return float("inf") when ZeroDivisionError is raised and maybe return float("NaN") if ValueError is raised in all of the magic math methods!

This is stated in the Python Docs. But ≥70% people don't know it!

P.S. Do you like JavaScript? Now you can get the similar behavior!

wyz23x2
  • 298
  • 4
  • 16
  • 1
    If you need to add additional information to your question then you should [edit](http://meta.stackexchange.com/a/21789/204922) your original question. Please only use the "Post Answer" button if you have found an answer to your question. Additionally, this post appears to be [off-topic](http://stackoverflow.com/help/on-topic) as per *This question does not appear to be about Stack Overflow or the Stack Exchange engine that powers the Stack Exchange network, within the scope defined in the help center*. – CallMePerox May 06 '20 at 11:50