

However, what we can do is to utilize Python’s way of dealing with floor function and utilize it in a slightly different fashion to derive a new way of expressing the ceiling function. What about ceiling? You may start to google but you might not be able to find anything on this immediately from Python’s documentation, since ceiling function does not comes with it’s own operator like floor function. If x is not a float, delegates to x.floor, which should return an Integral value. However, I seems to have knack of finding the most unorthodox way of doing things, which led to discover uncommon ways to express my code.ĭuring the older days during my first foray into Python, I came across this wonderful way of expressing floor: # Alternative to: # b = math.floor( 10 / 3 ) b = 10 // 3ĭouble slashes, and that is all for expressing math.floor(x / y) simply. floor (x) ¶ Return the floor of x, the largest integer less than or equal to x. It is just a simple math.ceil(x / y) and math.floor(x / y) respectively, when performing a division, right? Yes, that is correct!

You probably have used ceiling and floor mathematical functions in Python. The ceil() function approximates the given number to the smallest integer, greater than or. For lazy readers, you may just skip to the end for the TL DR cheatsheet version of this article The following two functions are called representation functions.
