1

What's difference between / and // operator in python?

  • Possible duplicate of [In Python 2, what is the difference between '/' and '//' when used for division?](https://stackoverflow.com/questions/183853/in-python-2-what-is-the-difference-between-and-when-used-for-division) – Alperen Nov 11 '17 at 10:34

2 Answers2

1

I just find out my own answer by trying this code so may be helpful for others

Operator: / Name: Division

This is arithmetic operator and it is used to divide two values and its shows result in float

a = 10
b = 2
c= a/b   # a is being divided by b and we will get result in float
print(c) # result will be: 5.0

Operator: // Name: Division

This is also arithmetic operator and it is used to divide two values and it shows result in int

a = 10
b = 3
c = a//b # as is being divided by b and we will get result in int
print(c) # #result will be: 3 instead of 3.3333333333333335
1

// is a division operation that returns an integer by discarding the remainder. This is the standard form of division using the / in most programming languages. However, Python 3 changed the behavior of / to perform floating-point division even if the arguments are integers. The // operator was introduced in Python 2.6 and Python 3 to provide an integer-division operator that would behave consistently between Python 2 and Python 3.

This means:python 3

 3/2= 1.5
 3//2=1
mak-273
  • 62
  • 1
  • 7