{"id":12051,"date":"2021-11-18T05:29:40","date_gmt":"2021-11-18T05:29:40","guid":{"rendered":"https:\/\/linuxways.net\/?p=12051"},"modified":"2024-03-25T02:10:46","modified_gmt":"2024-03-25T02:10:46","slug":"python-divmod-function","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/scripting\/python-divmod-function\/","title":{"rendered":"Python divmod() function"},"content":{"rendered":"<h2><a id=\"post-12051-_u30tm8gx65h0\"><\/a>Introduction<\/h2>\n<p>The divmod() function is used to divide and return the result as an integer and the remainder of the two entered numbers. This is a common math operation in python to help solve math problems. Maybe it will help a lot in the school&#8217;s math program.<\/p>\n<p>And we will show you how to use the divmod() function in Python as you go through it below. Hope you understand.<\/p>\n<h2>Example<\/h2>\n<pre>\r\nx = divmod(7, 2)\r\n\r\nprint(x)\r\n<\/pre>\n<p>Output:<\/p>\n<pre>\r\n<strong>(3, 1)<\/strong><\/pre>\n<h2>Definition<\/h2>\n<p>The divmod() function returns 2 values: integer and remainder.<\/p>\n<h2>The syntax<\/h2>\n<pre>\r\ndivmod(x, y)\r\n<\/pre>\n<p><strong>Parameter Values<\/strong>:<\/p>\n<pre>\r\nx: dividend\r\n\r\ny: divisor\r\n<\/pre>\n<h2>More examples<\/h2>\n<p><strong>Example 1<\/strong>: Basic divmod()<\/p>\n<pre>\r\nx = divmod(9, 4)\r\n\r\ny = divmod(7, 2)\r\n\r\nprint(\"x = \", x)\r\n\r\nprint(\"y = \", y)\r\n<\/pre>\n<p>Output:<\/p>\n<pre>\r\n<strong>x = (2, 1)<\/strong>\r\n\r\n<strong>y = (3, 1)<\/strong>\r\n<\/pre>\n<p><strong>Example 2<\/strong>:<\/p>\n<pre>\r\ndivmod() combines input() function\r\n\r\nprint(\"Enter x number:\")\r\n\r\nx = int(input())\r\n\r\nprint(\"Enter y number:\")\r\n\r\ny = int(input())\r\n\r\nz = divmod(x, y)\r\n\r\nprint(\"Result: \",z)\r\n<\/pre>\n<p>Output:<\/p>\n<pre>\r\n<strong>Enter x number: 5<\/strong>\r\n\r\n<strong>Enter y number: 2<\/strong>\r\n\r\n<strong>Result: (2, 1)<\/strong>\r\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>Hope you understood the tutorial on how to use the divmod() function in Python.<\/p>\n<p>Thanks for reading!<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction The divmod() function is used to divide and return the result as an integer and the remainder of the two entered numbers. This is a common math&hellip;<\/p>","protected":false},"author":110,"featured_media":12062,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[168],"tags":[10],"class_list":["post-12051","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-python"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/12051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=12051"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/12051\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/12062"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=12051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=12051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=12051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}