>>> 10/4

2

>>> -10/4

-3

Why is it ? I think -10/4 = -2

And now, the Modulus in Python:

>>> 10%4

2

>>> -10%4

2

The operator -10/4 has remainder is -2, not 2

Next:

>>> 10%-4

-2

The operator 10/-4 has remainer is 2, not 2

Next:

>>> 11%4

3

>>> -11%4

1

>>> 11%-4

-1

I cant understand this case.

# Division and Modulus operators in Python

Page 1 of 1## 6 Replies - 4796 Views - Last Post: 01 April 2010 - 08:00 PM

##
**Replies To:** Division and Modulus operators in Python

### #2

## Re: Division and Modulus operators in Python

Posted 16 July 2007 - 10:47 PM

### #3

## Re: Division and Modulus operators in Python

Posted 17 July 2007 - 12:53 PM

hahaha...same question on two forums

### #4

## Re: Division and Modulus operators in Python

Posted 31 July 2007 - 03:17 AM

Although I have been using python for last four months .. I never noticed this ..

very interesting though.

very interesting though.

### #5

## Re: Division and Modulus operators in Python

Posted 27 August 2007 - 05:25 AM

A short a answer:

use:

10.0/4

use:

10.0/4

### #6 Guest_K.Kishore*

## Re: Division and Modulus operators in Python

Posted 29 March 2010 - 11:43 PM

>>> 10%4

2

>>> -10%4

2

Yes, The operator -10/4 has remainder is -2

In this case you have to type in this way

>>> -(10%4)

Next:

>>> 11%4

3

>>> -11%4

1

>>> 11%-4

-1

In this, The remainder is

4 )11(3 , then you get remainder is -1

12

4 )-11 (3 , then you get remainder is 1

12

2

>>> -10%4

2

Yes, The operator -10/4 has remainder is -2

In this case you have to type in this way

>>> -(10%4)

Next:

>>> 11%4

3

>>> -11%4

1

>>> 11%-4

-1

In this, The remainder is

4 )11(3 , then you get remainder is -1

12

4 )-11 (3 , then you get remainder is 1

12

### #7

## Re: Division and Modulus operators in Python

Posted 01 April 2010 - 08:00 PM

Thanks for your answer, but this topic is nearly 3 years old!

Page 1 of 1