Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Numeric

hi! I am at the Numeric lesson at Python and while 4* 2 = 8, 16 / 4 = 4.0. Why does division equals a number with decimal?

1 Answer

Steven Parker
Steven Parker
229,732 Points

Normal division in Python produces a floating-point result. If you want an integer result instead, there's a different operator for that — the double-slash ("//").

Just be aware than when you use that operator, any fractional part in the result will be truncated.
So for example, 5 // 2 will produce just 2 as the result.