- 3

is 5//2 the same as int(5/2)

do they both output the integer 2?

28th Jun 2016, 3:14 AM
Yi Jiang
Yi Jiang - avatar
5 Answers
+ 1
Yes they are the same. // gives the quotient which is 2 In this case. The function int will give the integer value of 5/2=2.5 which is 2.
28th Jun 2016, 4:34 AM
Sanya Rastogi
Sanya Rastogi - avatar
0
in python they both are equal
28th Jun 2016, 4:02 AM
Nishant Sardana
Nishant Sardana - avatar
0
they are not the same floor division gives the greatest integer less than or equal to the answer of 20/3, if code is print(20//6) you get output 3 but if the code is print(-20//6) you get the output as -4 it does not just truncate the value of the float( the one you get by just dividing) , it is clear in the case of negative numbers but print(int(-20/6)) will always give -3 upvote if you see the difference 😀
30th Jul 2016, 4:54 PM
Tom Joseph
Tom Joseph - avatar
- 1
yes
28th Jun 2016, 4:02 AM
Nishant Sardana
Nishant Sardana - avatar