{"id":14977,"date":"2021-07-29T07:51:16","date_gmt":"2021-07-29T02:21:16","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=14977"},"modified":"2021-07-29T07:51:19","modified_gmt":"2021-07-29T02:21:19","slug":"python-comparators","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-comparators\/","title":{"rendered":"The Secret of Comparators | Comparison Operators in Python"},"content":{"rendered":"\n<p class=\"has-drop-cap\">Here we are going to see about comparators in python. We are going to learn about all the six python comparators and how to use them. And we are going to know about how to compare lists and strings. <\/p>\n\n\n\n<p><strong>Comparators are used to take two values and compare them together. It compares and produces the boolean values. It is commonly used with numerical values, but it can be used with other data types as well so.<\/strong><\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#What_are_the_Comparators_in_Python\" >What are the Comparators in Python?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Greater_than_operator\" >Greater than operator<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Example_1\" >Example 1<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Example_2\" >Example 2<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Example_3\" >Example 3<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Greater_than_or_equal_to_operator\" >Greater than or equal to operator<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Example\" >Example<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Less_than_operator\" >Less than operator<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Example-2\" >Example<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Less_than_or_equal_to_operator\" >Less than or equal to operator<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Example-3\" >Example<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Equal_to_operator\" >Equal to operator<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Example-4\" >Example<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Not_equal_to_operator\" >Not equal to operator<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Example-5\" >Example<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Comparing_a_list\" >Comparing a list<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Code\" >Code<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Comparing_a_string_using_python_comparators\" >Comparing a string using python comparators<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Code-2\" >Code<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#How_to_overload_these_comparators_in_classes\" >How to overload these comparators in classes?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Code-3\" >Code<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Frequently_asked_questions_related_to_Comparators\" >Frequently asked questions related to Comparators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#Trending_Right_Now\" >Trending Right Now<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-what-are-the-comparators-in-python\"><span class=\"ez-toc-section\" id=\"What_are_the_Comparators_in_Python\"><\/span>What are the Comparators in Python?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The Python Comparators commonly take two values and compares them. It normally produces boolean values as True or False. For example, if we give 3&gt;2, it produces the result as True. We have six comparators in Python. They are,<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table class=\"has-blush-light-purple-gradient-background has-background\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Python <strong>Comparators<\/strong><\/th><th class=\"has-text-align-left\" data-align=\"left\"><strong>Symbols<\/strong><\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">greater than<\/td><td class=\"has-text-align-left\" data-align=\"left\">&gt;<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">greater than or equal to<\/td><td class=\"has-text-align-left\" data-align=\"left\">&gt;=<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">less than<\/td><td class=\"has-text-align-left\" data-align=\"left\">&lt;<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">less than or equal to<\/td><td class=\"has-text-align-left\" data-align=\"left\">&lt;=<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">equal to <\/td><td class=\"has-text-align-left\" data-align=\"left\">==<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">not equal to<\/td><td class=\"has-text-align-left\" data-align=\"left\">!=<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-greater-than-operator\"><span class=\"ez-toc-section\" id=\"Greater_than_operator\"><\/span>Greater than operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p> <strong>&gt; <\/strong>is a symbol used for greater-than operator. It compares the left side value and the right side value. If the left-side value is greater, it returns True. Otherwise, it returns False.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-1\"><span class=\"ez-toc-section\" id=\"Example_1\"><\/span> Example 1<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; 3 &gt; 2\nTrue\n<\/pre><\/div>\n\n\n<p>Here it returns True because three is greater than 2.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-2\"><span class=\"ez-toc-section\" id=\"Example_2\"><\/span> Example 2<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; &quot;Python&quot;&gt;&quot;python&quot;\nFalse\n<\/pre><\/div>\n\n\n<p>Here it checks based on the <a href=\"http:\/\/www.pythonpool.com\/python-ascii-to-string\/\" target=\"_blank\" rel=\"noopener\">ASCII<\/a> value. The ASCII value for P is 80 and for p is 112. So the ASCII value of &#8220;p&#8221; is greater than &#8220;P&#8221;; hence it returns False.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-3\"><span class=\"ez-toc-section\" id=\"Example_3\"><\/span> Example 3<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; len(&quot;return&quot;)&gt;len(&quot;ad&quot;)\nTrue\n<\/pre><\/div>\n\n\n<p id=\"h-\">Now we are going to compare based on the length of the string. For that, we are using the <strong>len() <\/strong>function. It returns True because the length of the return is greater.<\/p>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-kilo monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Popular now<\/span><span class=\"monsterinsights-inline-popular-posts-border\" ><\/span><span class=\"monsterinsights-inline-popular-posts-border-2\" ><\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\">[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-greater-than-or-equal-to-operator\"><span class=\"ez-toc-section\" id=\"Greater_than_or_equal_to_operator\"><\/span>Greater than or equal to operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>&gt;=<\/strong> is a symbol used for greater than or equal to operator. It compares the left side value and the right side value. If the left-side value is greater than or equal, it returns True. Otherwise, it returns False. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example\"><span class=\"ez-toc-section\" id=\"Example\"><\/span> Example <span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; 3&lt;=4\nTrue\n&gt;&gt;&gt; 4&gt;=4\nTrue\n<\/pre><\/div>\n\n\n<p>In the first statement, it returns True because 4 is greater than 3. The other statement also returns True because 4 is equal to 4.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-less-than-operator\"><span class=\"ez-toc-section\" id=\"Less_than_operator\"><\/span>Less than operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>&lt;<\/strong> is a symbol used for the less-than operator. It compares the left value and right value. If the left-side value is lesser, it returns True. Otherwise, it returns False. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-4\"><span class=\"ez-toc-section\" id=\"Example-2\"><\/span> Example <span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; 4&lt;7\nTrue\n<\/pre><\/div>\n\n\n<p>4 is less than 7, so the result is True.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-less-than-or-equal-to-operator\"><span class=\"ez-toc-section\" id=\"Less_than_or_equal_to_operator\"><\/span>Less than or equal to operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p> <strong>&lt;=<\/strong> is a symbol used for less than or equal to operator. It compares the left side value and the right side value. If the left-side value is lesser or equal, it returns True. Otherwise, it returns False. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-5\"><span class=\"ez-toc-section\" id=\"Example-3\"><\/span> Example <span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; 4&lt;6\nTrue\n&gt;&gt;&gt; 9&lt;=9\nTrue\n<\/pre><\/div>\n\n\n<p>4 is less than 6, so the result is True, and 9 is equal to 9, so it returns True.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-equal-to-operator\"><span class=\"ez-toc-section\" id=\"Equal_to_operator\"><\/span>Equal to operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p> <strong>==<\/strong> is a symbol used for equal to operator. It compares the left value and right value. If the left-side value is equal to the right-side value, it returns True. Otherwise, it returns False.  <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-6\"><span class=\"ez-toc-section\" id=\"Example-4\"><\/span> Example <span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; 6==0\nFalse\n<\/pre><\/div>\n\n\n<p>6 is not equal to 0, so it returns False<\/p>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-delta monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-icon\" style=\"\"><svg width=\"14\" height=\"19\" viewBox=\"0 0 14 19\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M7.875 0.899463C7.875 1.59183 8.0816 2.24711 8.49479 2.8653C8.93229 3.48349 9.44271 4.06458 10.026 4.60859C10.6337 5.15259 11.2292 5.73369 11.8125 6.35188C12.4201 6.97007 12.9306 7.76135 13.3438 8.72572C13.7812 9.66537 14 10.7163 14 11.8785C14 13.832 13.3073 15.5011 11.9219 16.8858C10.5608 18.2953 8.92014 19 7 19C5.07986 19 3.42708 18.2953 2.04167 16.8858C0.680556 15.5011 0 13.832 0 11.8785C0 9.94973 0.668403 8.28062 2.00521 6.87116C2.27257 6.57443 2.58854 6.50024 2.95312 6.64861C3.31771 6.79697 3.5 7.08134 3.5 7.50171V10.6545C3.5 11.3221 3.71875 11.8908 4.15625 12.3607C4.61806 12.8305 5.16493 13.0654 5.79688 13.0654C6.45312 13.0654 7.01215 12.8428 7.47396 12.3978C7.93576 11.9279 8.16667 11.3592 8.16667 10.6916C8.16667 10.2712 8.04514 9.86318 7.80208 9.46754C7.58333 9.0719 7.31597 8.71336 7 8.3919C6.68403 8.07044 6.34375 7.73662 5.97917 7.39043C5.63889 7.04425 5.34722 6.66097 5.10417 6.2406C4.88542 5.82024 4.73958 5.35041 4.66667 4.83114C4.59375 4.31186 4.67882 3.68131 4.92188 2.93948C5.18924 2.17293 5.63889 1.33219 6.27083 0.417277C6.51389 0.0463641 6.84201 -0.0772735 7.25521 0.0463641C7.6684 0.170002 7.875 0.454368 7.875 0.899463Z\" fill=\"#EB5757\"><\/path><\/svg><\/span><span class=\"monsterinsights-inline-popular-posts-label\" >Trending<\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\" style=\"color:#000000;font-size:17px;\" href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\">[Fixed] nameerror: name Unicode is not defined<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-not-equal-to-operator\"><span class=\"ez-toc-section\" id=\"Not_equal_to_operator\"><\/span>Not equal to operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p> <strong>!=<\/strong> is a symbol used for not equal to operator. It compares the left value and right value. If the left-side value is not equal to the right-side value, it returns True. Otherwise, it returns False.   <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-7\"><span class=\"ez-toc-section\" id=\"Example-5\"><\/span>Example<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&gt;&gt;&gt; 4!=4\nFalse\n<\/pre><\/div>\n\n\n<p>4 is equal to 4, but it is given as not equal to, so it returns False.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-comparing-a-list\"><span class=\"ez-toc-section\" id=\"Comparing_a_list\"><\/span>Comparing a list<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Until we saw about all the comparators available in python, now using those comparators, we will compare the list.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-code\"><span class=\"ez-toc-section\" id=\"Code\"><\/span>Code<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlst1=&#x5B;2,5,6]\nlst2=&#x5B;4,2,9]\nif lst1&gt;lst2:\n    print(&quot;list1 is greater than list2&quot;)\nelif lst1&lt;lst2:\n    print(&quot;list2 is greater than list1&quot;)\nelse:\n    print(&quot;both the list are equal&quot;)\n<\/pre><\/div>\n\n\n<p>First, we are giving two lists to compare. And then using if-else statements to compare the lists. The size of list1 and list2 is the same, but we are giving different elements in both lists. The elements in list2 are greater than the elements in list1. So it returns the result of list2 is greater than list1.<\/p>\n\n\n\n<p class=\"has-medium-font-size\" id=\"h-output\"><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Enter size of list:2\nEnter any number:4\nEnter any number:7\n\nEnter size of list:2\nEnter any number:9\nEnter any number:7\nlist2 is greater than list1<\/pre>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" style=\"font-size:19px\"><strong>Must Read |<\/strong> <a href=\"http:\/\/www.pythonpool.com\/remove-quotes-from-string-python\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span style=\"text-decoration: underline;\">How to Remove Quotes From a String in Python<\/span><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-comparing-a-string-using-python-comparators\"><span class=\"ez-toc-section\" id=\"Comparing_a_string_using_python_comparators\"><\/span>Comparing a string using python comparators<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Now we are using the comparators to compare the length of the strings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-code-1\"><span class=\"ez-toc-section\" id=\"Code-2\"><\/span>Code<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nstr1=&quot;Python&quot;\nstr2=&quot;Programming&quot;\nif len(str1)&gt;len(str2):\n    print(&quot;The length of the &quot;,str1,&quot;is greater than the length of&quot;,str2)\nelif len(str1)&lt;len(str2):\n     print(&quot;The length of the &quot;,str2,&quot;is greater than the length of&quot;,str1)\nelse:\n    print(&quot;Both the strings are in same length&quot;)\n<\/pre><\/div>\n\n\n<p>Here we are comparing the strings based on their length. For that, we are using&nbsp;th<strong>e len()<\/strong>&nbsp;function. The length of string2 is greater than string2. So it returns Programming is greater than Python.<\/p>\n\n\n\n<p class=\"has-medium-font-size\" id=\"h-output-1\"><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">The length of the  Programming is greater than the length of Python.<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-overload-these-comparators-in-classes\"><span class=\"ez-toc-section\" id=\"How_to_overload_these_comparators_in_classes\"><\/span>How to overload these comparators in classes?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>One operator that performs several tasks is known as <a href=\"https:\/\/docs.python.org\/3\/reference\/datamodel.html\" target=\"_blank\" rel=\"noreferrer noopener\">overloading<\/a>. For example, if we take, + operator is used for several purposes like the addition of two integers, concatenation, and merging two lists.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-code-2\"><span class=\"ez-toc-section\" id=\"Code-3\"><\/span>Code<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nclass comparators:\n    def __init__(self, a):\n        self.a = a\n    def __gt__(self, other):\n        if(self.a&gt;other.a):\n            return True\n        else:\n            return False\nobj1 =  comparators(10)\nobj2 =  comparators(53)\nif(obj1&gt;obj2):\n    print(&quot;obj1 is greater than obj2&quot;)\nelse:\n    print(&quot;obj2 is greater than obj1&quot;)\n<\/pre><\/div>\n\n\n<p>First, we created a class named&nbsp;<strong>&#8220;comparators&#8221;<\/strong>. And then created objects. In this, we have given obj1=comparators(10) and obj2=comparators(53). It compares both the object and returns, which is greater.&nbsp;<\/p>\n\n\n\n<p class=\"has-medium-font-size\" id=\"h-output-2\"><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">obj2 is greater than obj1<\/pre>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-alpha monsterinsights-popular-posts-styled\" style=\"background-color:#91D2FA;\"><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Trending<\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\">[Solved] runtimeerror: cuda error: invalid device ordinal<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-frequently-asked-questions-related-to-comparators\"><span class=\"ez-toc-section\" id=\"Frequently_asked_questions_related_to_Comparators\"><\/span>Frequently asked questions related to Comparators<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1627461726886\"><strong class=\"schema-faq-question\">1. How many types of comparators are available in Python?<\/strong> <p class=\"schema-faq-answer\">Six types of comparators are available in Python.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1627461785894\"><strong class=\"schema-faq-question\">2. How does the comparator work?<\/strong> <p class=\"schema-faq-answer\"> Comparators are used to take two values and compare them together. It compares and produces the boolean values. It is commonly used with numerical values, but it can be used with other data types as well so.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1627461907515\"><strong class=\"schema-faq-question\">3. Does the comparator returns a boolean value?<\/strong> <p class=\"schema-faq-answer\">Yes, the comparator returns boolean values as True or False.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1627462005032\"><strong class=\"schema-faq-question\">4. Which function is used to compare a string?<\/strong> <p class=\"schema-faq-answer\">len() function is used to compare a string.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1627478913027\"><strong class=\"schema-faq-question\">5. What are the types of comparators?<\/strong> <p class=\"schema-faq-answer\">greater than, greater than or equal to, less than, less than or equal to, equal to, not equal to are the types of comparators.<\/p> <\/div> <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here we have seen some comparators available in python. Totally we have six comparators in python. The above shown are just an example we can do a lot of things using comparators.<\/p>\n\n\n<div class=\"monsterinsights-widget-popular-posts monsterinsights-widget-popular-posts-charlie monsterinsights-popular-posts-styled monsterinsights-widget-popular-posts-columns-1\"><h2 class=\"monsterinsights-widget-popular-posts-widget-title\"><span class=\"ez-toc-section\" id=\"Trending_Right_Now\"><\/span>Trending Right Now<span class=\"ez-toc-section-end\"><\/span><\/h2><ul class=\"monsterinsights-widget-popular-posts-list\"><li style=\"border-color:#CD3034;\"><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" style=\"color:#000000;font-size:17px;\">[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li style=\"border-color:#CD3034;\"><a href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" style=\"color:#000000;font-size:17px;\">[Fixed] nameerror: name Unicode is not defined<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li style=\"border-color:#CD3034;\"><a href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" style=\"color:#000000;font-size:17px;\">[Solved] runtimeerror: cuda error: invalid device ordinal<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><li style=\"border-color:#CD3034;\"><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-type-numpy-ndarray-doesnt-define-__round__-method\/\"><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" style=\"color:#000000;font-size:17px;\">[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><\/div><\/div><\/a><\/li><\/ul><\/div><p><\/p>","protected":false},"excerpt":{"rendered":"<p>Here we are going to see about comparators in python. We are going to learn about all the six python comparators and how to use &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"The Secret of Comparators | Comparison Operators in Python\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/#more-14977\" aria-label=\"More on The Secret of Comparators | Comparison Operators in Python\">Read more<\/a><\/p>\n","protected":false},"author":22,"featured_media":15002,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[4375,4374],"class_list":["post-14977","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-comparing-value-in-python","tag-comparison-operators-in-python","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The Secret of Comparators | Comparison Operators in Python<\/title>\n<meta name=\"description\" content=\"Python Comparators are used to take two values and compare them together and produce the boolean values. six comparators are there in python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-comparators\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Secret of Comparators | Comparison Operators in Python\" \/>\n<meta property=\"og:description\" content=\"Here we are going to see about comparators in python. We are going to learn about all the six python comparators and how to use them. And we are going to\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-comparators\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-29T02:21:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-29T02:21:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/The-Secret-of-Comparators-in-Python.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Priyalakshmi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Priyalakshmi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/\"},\"author\":{\"name\":\"Priyalakshmi\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/83e6e22a6c461cc1a8445bb473db2f20\"},\"headline\":\"The Secret of Comparators | Comparison Operators in Python\",\"datePublished\":\"2021-07-29T02:21:16+00:00\",\"dateModified\":\"2021-07-29T02:21:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/\"},\"wordCount\":920,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/The-Secret-of-Comparators-in-Python.webp\",\"keywords\":[\"comparing value in python\",\"comparison operators in python\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-comparators\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-comparators\/\",\"name\":\"The Secret of Comparators | Comparison Operators in Python\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/The-Secret-of-Comparators-in-Python.webp\",\"datePublished\":\"2021-07-29T02:21:16+00:00\",\"dateModified\":\"2021-07-29T02:21:19+00:00\",\"description\":\"Python Comparators are used to take two values and compare them together and produce the boolean values. six comparators are there in python.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461726886\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461785894\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461907515\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627462005032\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627478913027\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-comparators\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/The-Secret-of-Comparators-in-Python.webp\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/The-Secret-of-Comparators-in-Python.webp\",\"width\":1200,\"height\":628,\"caption\":\"python comparators\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The Secret of Comparators | Comparison Operators in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/83e6e22a6c461cc1a8445bb473db2f20\",\"name\":\"Priyalakshmi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8f1aadb3b77a89fe5776d41fb52aec63200d0e68e92c71cb9aafac7fb4456696?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8f1aadb3b77a89fe5776d41fb52aec63200d0e68e92c71cb9aafac7fb4456696?s=96&d=wavatar&r=g\",\"caption\":\"Priyalakshmi\"}},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461726886\",\"position\":1,\"url\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461726886\",\"name\":\"1. How many types of comparators are available in Python?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Six types of comparators are available in Python.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461785894\",\"position\":2,\"url\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461785894\",\"name\":\"2. How does the comparator work?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\" Comparators are used to take two values and compare them together. It compares and produces the boolean values. It is commonly used with numerical values, but it can be used with other data types as well so.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461907515\",\"position\":3,\"url\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461907515\",\"name\":\"3. Does the comparator returns a boolean value?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes, the comparator returns boolean values as True or False.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627462005032\",\"position\":4,\"url\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627462005032\",\"name\":\"4. Which function is used to compare a string?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"len() function is used to compare a string.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627478913027\",\"position\":5,\"url\":\"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627478913027\",\"name\":\"5. What are the types of comparators?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"greater than, greater than or equal to, less than, less than or equal to, equal to, not equal to are the types of comparators.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"The Secret of Comparators | Comparison Operators in Python","description":"Python Comparators are used to take two values and compare them together and produce the boolean values. six comparators are there in python.","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:\/\/www.pythonpool.com\/python-comparators\/","og_locale":"en_US","og_type":"article","og_title":"The Secret of Comparators | Comparison Operators in Python","og_description":"Here we are going to see about comparators in python. We are going to learn about all the six python comparators and how to use them. And we are going to","og_url":"https:\/\/www.pythonpool.com\/python-comparators\/","og_site_name":"Python Pool","article_published_time":"2021-07-29T02:21:16+00:00","article_modified_time":"2021-07-29T02:21:19+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/The-Secret-of-Comparators-in-Python.webp","type":"image\/webp"}],"author":"Priyalakshmi","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Priyalakshmi","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-comparators\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/"},"author":{"name":"Priyalakshmi","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/83e6e22a6c461cc1a8445bb473db2f20"},"headline":"The Secret of Comparators | Comparison Operators in Python","datePublished":"2021-07-29T02:21:16+00:00","dateModified":"2021-07-29T02:21:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/"},"wordCount":920,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/The-Secret-of-Comparators-in-Python.webp","keywords":["comparing value in python","comparison operators in python"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-comparators\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.pythonpool.com\/python-comparators\/","url":"https:\/\/www.pythonpool.com\/python-comparators\/","name":"The Secret of Comparators | Comparison Operators in Python","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/The-Secret-of-Comparators-in-Python.webp","datePublished":"2021-07-29T02:21:16+00:00","dateModified":"2021-07-29T02:21:19+00:00","description":"Python Comparators are used to take two values and compare them together and produce the boolean values. six comparators are there in python.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461726886"},{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461785894"},{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461907515"},{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627462005032"},{"@id":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627478913027"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-comparators\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-comparators\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/The-Secret-of-Comparators-in-Python.webp","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/07\/The-Secret-of-Comparators-in-Python.webp","width":1200,"height":628,"caption":"python comparators"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-comparators\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"The Secret of Comparators | Comparison Operators in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/83e6e22a6c461cc1a8445bb473db2f20","name":"Priyalakshmi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8f1aadb3b77a89fe5776d41fb52aec63200d0e68e92c71cb9aafac7fb4456696?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8f1aadb3b77a89fe5776d41fb52aec63200d0e68e92c71cb9aafac7fb4456696?s=96&d=wavatar&r=g","caption":"Priyalakshmi"}},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461726886","position":1,"url":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461726886","name":"1. How many types of comparators are available in Python?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Six types of comparators are available in Python.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461785894","position":2,"url":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461785894","name":"2. How does the comparator work?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":" Comparators are used to take two values and compare them together. It compares and produces the boolean values. It is commonly used with numerical values, but it can be used with other data types as well so.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461907515","position":3,"url":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627461907515","name":"3. Does the comparator returns a boolean value?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes, the comparator returns boolean values as True or False.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627462005032","position":4,"url":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627462005032","name":"4. Which function is used to compare a string?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"len() function is used to compare a string.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627478913027","position":5,"url":"https:\/\/www.pythonpool.com\/python-comparators\/#faq-question-1627478913027","name":"5. What are the types of comparators?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"greater than, greater than or equal to, less than, less than or equal to, equal to, not equal to are the types of comparators.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/14977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=14977"}],"version-history":[{"count":27,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/14977\/revisions"}],"predecessor-version":[{"id":15016,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/14977\/revisions\/15016"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/15002"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=14977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=14977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=14977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}