Marlon Gutjahr
last year
Marloncountry asked

When should I use the // division symbol instead of the / symbol?

Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hi there! Good question — understanding the difference between // and / is important when dividing numbers in Python.

1. When to use /

When you use /, it performs division and will always return a float (decimal number), even if the result is a whole number. This operation is called floating-point division.

Example:

50 / 8 = 6.25

2. When to use //

On the other hand, // is used for integer division, which means it gives you the integer part of the division result, discarding any remainder or fractional part.

This is particularly useful when you want to evenly distribute items (like chocolates) and only care about whole numbers or integers.

example: 50 // 8 = 6

So, in your "Divide Chocolates" lesson, you use // to find out how many complete chocolates each child will get, ignoring any leftover ones.

This helps ensure each child gets exactly six chocolates, with // handling the whole number part effectively.

Hope this helps! Feel free to ask if you have more questions or need further clarification.

Python
This question was asked as part of the Practice: Python Basics course.