1

An example:

> dhcp-wifi-8021x-155-41-14-238:~ user$ python
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:30:03) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 0/-1
-0.0

Why does Python return -0.0 instead of 0.0?

hannah
  • 889
  • 4
  • 13
  • 27
  • 1
    Look at this: https://stackoverflow.com/a/5535239/3780625 – Maxouille Mar 26 '19 at 14:59
  • 1
    @Maxouille OP is using Python 3. – Ma0 Mar 26 '19 at 15:00
  • This post is just to explain that this is the normal behavior of division. `0` or `-0` are the same. Division works like multiplication: - / - and + / + returns a positive value while - / + and + / - returns a negative number. – Maxouille Mar 26 '19 at 15:02
  • You make it look like there's something weird with the minus-sign, but in fact `6/2` also gives `3.0`, and `8/4` gives `2.0`, so you seem to get a floating point number at every division. – Dominique Mar 26 '19 at 15:10
  • You can also check this using the `type()` function : `type(6)` gives ``, while `type(6/3)` gives ``. If you really need the integer division, you need to put double slashes, as you can see here: `6//2` gives `3`, `type(6//2)` gives ``. – Dominique Mar 26 '19 at 15:16

0 Answers0