- 3
is 5//2 the same as int(5/2)
do they both output the integer 2?
5 Antworten
+ 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.
0
in python they both are equal
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 😀
- 1
yes