{"id":24099,"date":"2021-10-14T09:12:25","date_gmt":"2021-10-14T03:42:25","guid":{"rendered":"https:\/\/python-programs.com\/?p=24099"},"modified":"2021-11-05T20:53:04","modified_gmt":"2021-11-05T15:23:04","slug":"python-program-for-fabs-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-fabs-function\/","title":{"rendered":"Python Program for fabs() Function"},"content":{"rendered":"

In the previous article, we have discussed Python Program for copysign() Function<\/a>
\nfabs() Function in Python:<\/strong><\/p>\n

The math. fabs() method returns a float containing the absolute value of a number.<\/p>\n

The term absolute refers to a non-negative number. If the value has a negative sign, this removes it.<\/p>\n

This method, unlike Python abs(), always converts the value to a float value.<\/p>\n

Syntax:<\/strong><\/p>\n

math.fabs(x)<\/pre>\n

Parameters:<\/strong><\/p>\n

x: <\/strong>This is required. It is a number. If we try anything other than a number, we get a TypeError.<\/p>\n

Return Value: <\/strong>It returns a float value which represents the absolute value of x.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [1, -2, -3, 4]\r\nGiven first number = 45\r\nGiven second number = -70<\/pre>\n

Output:<\/strong><\/p>\n

The absolute value of above given number 45  =  45.0\r\nThe absolute value of above given number -70  =  70.0\r\nThe absolute value of given list element gvnlst[2] =  3.0<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [86, 34, 20, 10]\r\nGiven first number = 90\r\nGiven second number = -40<\/pre>\n

Output:<\/strong><\/p>\n

The absolute value of above given number 90  =  90.0\r\nThe absolute value of above given number -40  =  40.0\r\nThe absolute value of given list element gvnlst[1] =  34.0<\/pre>\n

Program for fabs() Function in Python<\/h2>\n