DEV Community

Sreeju S
Sreeju S

Posted on

abs() and round() function in python

Diffrence abs() and round() function in PYTHON

abs() function takes only one argument. In argument it basically takes number (for example integer and float). For complex number it returns the magnitude (for example : 3i+4j : √ (3)² + (4)² = 5).

Other Examples are :

var = 65.6

print ( var)
Enter fullscreen mode Exit fullscreen mode
OUTPUT: 65
Enter fullscreen mode Exit fullscreen mode

round() function can take two arguments. The first argument is the number which round-off value will be printed. The second argument is optional, tells up to which the given number (First argument) is rounded.

For Example :

print(round(51.6))

print(round(51.4))

print(round(2.665, 2))
Enter fullscreen mode Exit fullscreen mode
OUTPUT :
52
51
2.67
Enter fullscreen mode Exit fullscreen mode

NOTE: Both functions will give type error if the argument is not numbers.

Top comments (0)