KnowledgeBoat Logo

Computer Science

How does the // operator differ from the / operator? Give an example of where // would be needed.

Python Data Handling

29 Likes

Answer

The Division operator (/) divides its first operand by second operand and always returns the result as a float value whereas Floor Division operator (//) divides its first operand by second operand and truncates the fractional part of the result and returns it as an int value. Floor Division operator is useful in situations where we only need the integer part of the division operation result. For example, to determine how many minutes are there in some given number of seconds:

secs = 2565
mins = 2565 // 60

Answered By

14 Likes


Related Questions