{"id":10422,"date":"2022-11-10T08:17:01","date_gmt":"2022-11-10T08:17:01","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=10422"},"modified":"2023-05-12T05:31:59","modified_gmt":"2023-05-12T05:31:59","slug":"python-program-to-check-leap-year","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/","title":{"rendered":"Python Program to Check Leap Year"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg\" alt=\"\" \/><\/p>\n<p>To align the calendar year with the solar year, an extra day, or February 29, is added to the year every four years. It is well known that this year was a leap year. For many Python programming programs that work with dates and timers, checking for a leap year is essential. We will discuss the leap year program in Python using if else for better logic. If a year is a leap year, it must meet a variety of criteria, such as being divisible by 4, 100, and 400, as well as specific requirements for different calendar systems. The checking for leap years can be implemented by utilizing if-else statements or other logical constructs. Accurately determining leap years is a crucial aspect of time calculation that is necessary for many programs and applications.<\/p>\n<h2>What is a Leap Year?<\/h2>\n<p>A leap year is a year that has 366 days. For aligning the calendar year with the solar year, one extra day is added to this year. This extra day falls in the month of February, giving it 29 days instead of 28.<\/p>\n<h3>Mathematical Conditions for Leap Year<\/h3>\n<p>The following equations must be true for the leap year:<\/p>\n<ul>\n<li>The year must divide evenly by 400.<\/li>\n<li>The year should divide evenly by 4, but not by 100.<\/li>\n<\/ul>\n<h3>Examples of Leap Year<\/h3>\n<ol>\n<li>\n<p><strong>1947 is a leap year or not<\/strong><br \/>\nSince 1947 cannot be divided by either 4 or 400, it is not a leap year. Both of the above-mentioned mathematical prerequisites for a leap year are being disregarded by it.<\/p>\n<\/li>\n<li>\n<p><strong>1900 is a leap year or not<\/strong><br \/>\n1900 can be divided by 4, 100, but not 400. 1900 is not a leap year because it can be divided by 4 and 100. The requirement for a leap year is that the year must be divisible by 400 or by 4 but not by 100.<\/p>\n<\/li>\n<li>\n<p><strong>2000 is a leap year or not<\/strong><br \/>\nSince 2000 is divisible by 400, it is a leap year. It satisfies the first of the mathematical prerequisites for the leap year section, as was stated above.<\/p>\n<\/li>\n<li>\n<p><strong>2004 is a leap year or not<\/strong><br \/>\nSince 2004 is divisible by 4 but not by 100, it is a leap year. It satisfies the second of the mathematical conditions for the section on leap years that was mentioned before.<\/p>\n<\/li>\n<\/ol>\n<h2>Python Program to Check Leap Year<\/h2>\n<p>The following are different method to create leap year program in Python<\/p>\n<h3>1. Leap Year Program in Python using Calendar Module<\/h3>\n<p>The Calendar module offers extra calendar-related functions in addition to allowing you to output calendars similar to how the Unix cal program does. The start of the week is Monday, and the week ends on Sunday. Monday&#8217;s weekly index is 0, Tuesday&#8217;s is 1, and Wednesday&#8217;s is 2. Thursdays are three, Fridays are four, Saturdays are five, and Sundays are six. Using the setfirstweekday(integer) method, we may also change the first day of the week. The integer in this case represents the day&#8217;s weekly index.<\/p>\n<p>In the leap year program of python we will use the isleap() method of the calendar module.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre><code>isleap(year)<\/code><\/pre>\n<p>isleap() method returns the boolean value depending on whether the year is leap year or not. If the year is leap year then isleap() method will return True else False.<\/p>\n<p><strong>Code for leap year program in python using calendar module<\/strong><\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_10424 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_10424 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_10424 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_10424 .wpsm_nav-tabs > li.active > a, #tab_container_10424 .wpsm_nav-tabs > li.active > a:hover, #tab_container_10424 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_10424 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_10424 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_10424 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_10424 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_10424 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_10424 .wpsm_nav-tabs > li > a:hover , #tab_container_10424 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_10424 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_10424 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_10424 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_10424 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_10424 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_10424 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_10424 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_10424 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_10424 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_10424 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_10424 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_10424\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_10424\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_10424_1\" aria-controls=\"tabs_desc_10424_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Python<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_10424\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_10424_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\ndef checkLeapYear(year):\r\n#importing the calendar module\r\n    import calendar\r\n#returning boolean value based on given year is leap year or not\r\n    return(calendar.isleap(year))\r\n    \r\n# Driver Code for the leap year program in python \r\n#taking input (year) from the user\r\nyear = int(input(&quot;Enter the year: &quot;))\r\nif (checkLeapYear(year)):\r\n#if checkLeapYear function returns true\r\n    print(&quot;Leap Year&quot;)\r\nelse:\r\n#if checkLeapYear function returns false\r\n    print(&quot;Not a Leap Year&quot;)\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_10424 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_10424 a\"),jQuery(\"#tab-content_10424\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>OUTPUT:<\/strong><\/p>\n<pre><code>Enter the year: 2000\nLeap Year\nEnter the year: 1900\nNot a Leap Year<\/code><\/pre>\n<h3>2. Leap Year Program in Python using If-else Statement<\/h3>\n<ol>\n<li>Take a year as input from the user.<\/li>\n<li>Check if the year is divisible by 400, if yes return true else go to step 3.<\/li>\n<li>Check if the year is divisible by 4, if yes go to step 4, else step 5.<\/li>\n<li>Check if the year is divisible by 100, if no return true, else go to step 5.<\/li>\n<li>Return false.<\/li>\n<\/ol>\n<p><strong>Flowchart for a Leap Year Program in Python<\/strong><br \/>\nBelow is the step-by-step work of the leap year program in Python.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1683869442095-1%20%2841%29.png\" alt=\"\" \/><\/p>\n<p><strong>Source Code<\/strong><\/p>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_10425 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_10425 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_10425 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_10425 .wpsm_nav-tabs > li.active > a, #tab_container_10425 .wpsm_nav-tabs > li.active > a:hover, #tab_container_10425 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_10425 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_10425 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_10425 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_10425 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_10425 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_10425 .wpsm_nav-tabs > li > a:hover , #tab_container_10425 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_10425 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_10425 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_10425 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_10425 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_10425 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_10425 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_10425 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_10425 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_10425 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_10425 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_10425 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_10425\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_10425\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_10425_1\" aria-controls=\"tabs_desc_10425_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Python<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_10425\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_10425_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\ndef checkLeapYear(year):\r\n\tif year%400==0:\r\n# if year is divisible by 400, return True\r\n    \t\treturn True\r\n\telif year%4==0:\r\n# if year is divisible by 4,then check is it divisible by 100 or not\r\n    \t\tif year%100!=0:\r\n#if year is not divisible by 100, then return True\r\n        \t\t\treturn True\r\n    \t\telse:\r\n#if year is divisible by 100, then return False\r\n        \t\t\treturn False;\r\n    \r\n# Driver Code for the leap year program in python\r\n#taking input (year) from the user\r\nyear = int(input(&quot;Enter the year: &quot;))\r\nif (checkLeapYear(year)):\r\n#if checkLeapYear function returns true\r\n\tprint(&quot;Leap Year&quot;)\r\nelse:\r\n#if checkLeapYear function returns false\r\n\tprint(&quot;Not a Leap Year&quot;)\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_10425 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_10425 a\"),jQuery(\"#tab-content_10425\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>OUTPUT:<\/strong><\/p>\n<pre><code>Enter the year: 2000\nLeap Year\nEnter the year: 1900\nNot a Leap Year<\/code><\/pre>\n<p><strong>Summary<\/strong><\/p>\n<ul>\n<li>A leap year is a year with 366 days having one extra day in February month making it a month of 29 days.<\/li>\n<li>The mathematical condition for a year to be a leap year is it should get divisible by 400 or it should get divisible by 4 but not by 100.<\/li>\n<li>We can write a leap year program in Python in two ways, one using calendar modules\u2019 leap method and one by the simple if-else statement. <\/li>\n<li>Besides this, there are plenty of approaches to write a program to check leap year in Python. You have to practice more to figure out that.<\/li>\n<\/ul>\n<h2>FAQ Related to Python Program to Check Leap Year<\/h2>\n<p><strong>Q1. Does the Python programming language include a built-in function to check for leap years?<\/strong><br \/>\n<strong>Ans.<\/strong> Python does not have an in-built function to check whether a year is a leap or not.<\/p>\n<p><strong>Q2. Is 2032 a leap year?<\/strong><br \/>\n<strong>Ans.<\/strong> When dividing the number 2038 by 4, we obtain 508 as quotient and 0 as the remainder. Thus, it is perfectly divisible by 4, making it a leap year.<\/p>\n<p><strong>Q3. What is the list of leap years?<\/strong><br \/>\n<strong>Ans.<\/strong> The complete list of leap years in the first half of the 21st century is therefore 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036, 2040, 2044, and 2048.<\/p>\n<p><strong>Other Python Programs<\/strong><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-reverse-a-number\/\">Python program to reverse a number<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/heap\/python-program-for-heap-sort\/\">Python program for heap sort<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-check-armstrong-number\/\">Python program to check armstrong number<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-add-two-numbers\/\">Python program to add two numbers<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-convert-celsius-to-fahrenheit\/\">Python program to convert celsius to fahrenheit<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-find-factorial-of-a-number\/\">Python program to find factorial of a number<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-find-the-middle-of-a-linked-list-using-only-one-traversal\/\">Python program to find the middle of a linked list using only one traversal<\/a><br \/>\n<a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-reverse-a-linked-list\/\">Python program to reverse a linked list<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To align the calendar year with the solar year, an extra day, or February 29, is added to the year every four years. It is well known that this year was a leap year. For many Python programming programs that work with dates and timers, checking for a leap year is essential. We will discuss [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[154],"tags":[],"class_list":["post-10422","post","type-post","status-publish","format-standard","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Leap Year Program in Python | Python Program to Check Leap Year<\/title>\n<meta name=\"description\" content=\"Learn about the leap year and how to check whether a year is a leap year or not. We will also learn how to write program in Python to check leap year.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Leap Year Program in Python | Python Program to Check Leap Year\" \/>\n<meta property=\"og:description\" content=\"Learn about the leap year and how to check whether a year is a leap year or not. We will also learn how to write program in Python to check leap year.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-10T08:17:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-12T05:31:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Python Program to Check Leap Year\",\"datePublished\":\"2022-11-10T08:17:01+00:00\",\"dateModified\":\"2023-05-12T05:31:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/\"},\"wordCount\":882,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/\",\"name\":\"Leap Year Program in Python | Python Program to Check Leap Year\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg\",\"datePublished\":\"2022-11-10T08:17:01+00:00\",\"dateModified\":\"2023-05-12T05:31:59+00:00\",\"description\":\"Learn about the leap year and how to check whether a year is a leap year or not. We will also learn how to write program in Python to check leap year.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Program to Check Leap Year\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Leap Year Program in Python | Python Program to Check Leap Year","description":"Learn about the leap year and how to check whether a year is a leap year or not. We will also learn how to write program in Python to check leap year.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/","og_locale":"en_US","og_type":"article","og_title":"Leap Year Program in Python | Python Program to Check Leap Year","og_description":"Learn about the leap year and how to check whether a year is a leap year or not. We will also learn how to write program in Python to check leap year.","og_url":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2022-11-10T08:17:01+00:00","article_modified_time":"2023-05-12T05:31:59+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Python Program to Check Leap Year","datePublished":"2022-11-10T08:17:01+00:00","dateModified":"2023-05-12T05:31:59+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/"},"wordCount":882,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/","url":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/","name":"Leap Year Program in Python | Python Program to Check Leap Year","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg","datePublished":"2022-11-10T08:17:01+00:00","dateModified":"2023-05-12T05:31:59+00:00","description":"Learn about the leap year and how to check whether a year is a leap year or not. We will also learn how to write program in Python to check leap year.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1668066110061-Python%20Program%20to%20check%20leap%20year.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/python-program-to-check-leap-year\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/prepbytes.com\/blog\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Program to Check Leap Year"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/10422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=10422"}],"version-history":[{"count":5,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/10422\/revisions"}],"predecessor-version":[{"id":16276,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/10422\/revisions\/16276"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=10422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=10422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=10422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}