is 5//2 the same as int(5/2) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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
0
Yes, both 5//2 and int(5/2) in Python will output the integer value of 2. The // operator is known as the floor division operator, which performs division and returns the quotient as an integer, discarding any decimal points. In this case, 5//2 divides 5 by 2 and returns the integer quotient, which is 2. The int() function, when used with division, converts the result of the division to an integer by truncating any decimal places. So int(5/2) divides 5 by 2, resulting in 2.5, but the int() function converts it to the integer 2. Both 5//2 and int(5/2) will give you the same output, which is the integer value of 2, if you want free python tutorials then go here: https://pythondex.com
5th Jul 2023, 4:13 AM
Jarvis Silva
Jarvis Silva - avatar
- 1
yes
28th Jun 2016, 4:02 AM
Nishant Sardana
Nishant Sardana - avatar