{"id":24103,"date":"2021-10-14T08:32:40","date_gmt":"2021-10-14T03:02:40","guid":{"rendered":"https:\/\/python-programs.com\/?p=24103"},"modified":"2021-11-05T20:53:29","modified_gmt":"2021-11-05T15:23:29","slug":"python-program-for-fmod-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-fmod-function\/","title":{"rendered":"Python Program for fmod() Function"},"content":{"rendered":"

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

The remainder (modulo) of x\/y is returned by the math.fmod() method.<\/p>\n

The Python fmod() math function is used to compute the Modulo of the given arguments.<\/p>\n

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

math.fmod(x, y)<\/pre>\n

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

x:<\/strong> This is required. It is a positive or a negative number to divide.<\/p>\n

y:<\/strong> This is required. It is a positive or negative number with which to divide x<\/p>\n

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

If both x and y are zero, a ValueError is returned.
\nIf y = 0, a ValueError is returned.
\nIf x or y is not a number, it returns a TypeError.<\/p>\n

Return Value:<\/strong><\/p>\n

It returns a float value which indicates the remainder of x\/y.<\/p>\n

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

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

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

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

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

The remainder when given first number\/second number { 18 \/ 2 } =  0.0\r\nThe remainder when gvn_lst[2]\/given number { -3 \/ 5 } =  -3.0\r\nThe remainder of -16\/5 =  -1.0<\/pre>\n

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

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

Given list = [2, 4, 6, 8, 10]\r\nGiven first number =  8\r\nGiven second number =  5\r\nGiven number = 4<\/pre>\n

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

The remainder when given first number\/second number { 8 \/ 5 } =  3.0\r\nThe remainder when gvn_lst[3]\/given number { 8 \/ 4 } =  0.0\r\nThe remainder of -25\/-4 =  -1.0<\/pre>\n

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