What is the difference between / and //? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

What is the difference between / and //?

9th Aug 2020, 7:35 AM
Favour Kanyike
Favour Kanyike - avatar
3 Réponses
+ 6
5/2 = 2.5 5//2 = 2
9th Aug 2020, 7:45 AM
Arsenic
Arsenic - avatar
+ 6
stackoverflow.com/questions/183853/what-is-the-difference-between-and-when-used-for-division
9th Aug 2020, 7:45 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 4
Just adding some words to the sample of Arsenic: 5/2 = 2.5 -> this is a regular division. All divisions with this operator is giving a float number as result. 5//2 = 2 -> this is called a floor division. Only the whole number part is used here, the fractional part is ignored. the result is always an integer number.
9th Aug 2020, 1:39 PM
Lothar
Lothar - avatar