0

ceil method

What is the difference between math.ceil(x) and x.__ceil__()?

4th Feb 2022, 1:56 PM
shokin touch
1 Answer
+ 2
It's almost the same. The only difference is that you can redefine the function with magic method (__ceil__()). I think there's no point in redefining math.ceil() so don't use __ceil__(). https://code.sololearn.com/ch7rUkvBxKG6/?ref=app edit: In Python float is primitive type, not a class. You can't redifine math.ceil(float). My example is creating a new float-like object, not changing the function with a float parameter.
4th Feb 2022, 2:27 PM
C-MOON
C-MOON - avatar