

{"id":5321,"date":"2017-12-21T08:17:28","date_gmt":"2017-12-21T02:47:28","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=5321"},"modified":"2026-04-13T16:41:19","modified_gmt":"2026-04-13T11:11:19","slug":"python-operator","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-operator\/","title":{"rendered":"Python Operator &#8211; Types of Operators in Python"},"content":{"rendered":"<p>In this <strong>Python Operator<\/strong> tutorial, we will discuss what an operator is in the Python Programming Language. Operators help us perform different kinds of operations on values and variables in an easy way.<\/p>\n<p>By the end of this tutorial, you will understand how to use operators effectively in your Python programs. Learning these operators is important because they help turn simple values into useful code that can solve real-life problems.<\/p>\n<p>We will learn different types of Python Operators:\u00a0 Arithmetic,\u00a0 Relational,\u00a0 Assignment, Logical, Membership, Identity, and <strong>Bitwise Operators<\/strong> with their syntax and examples.<\/p>\n<p>So, let&#8217;s start the Python Operator Tutorial.<\/p>\n<h3>What is a Python Operator?<\/h3>\n<p>Python operator is a symbol that performs an operation on one or more operands. An operand is a variable or a value on which we perform the operation.<\/p>\n<p>Python Operator falls into 7 categories:<\/p>\n<ul>\n<li>Python Arithmetic Operator<\/li>\n<li>Python Relational\u00a0Operator<\/li>\n<li>Python Assignment\u00a0Operator<\/li>\n<li>Python Logical\u00a0Operator<\/li>\n<li>Python Membership\u00a0Operator<\/li>\n<li>Python Identity Operator<\/li>\n<li>Python Bitwise\u00a0Operator<\/li>\n<\/ul>\n<h3>1. Arithmetic Operators in Python<\/h3>\n<p>These Python arithmetic operators include Python operators for basic mathematical operations.<\/p>\n<div id=\"attachment_42918\" style=\"width: 717px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Arithmetic-Operator-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-42918\" class=\"wp-image-42918 \" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Arithmetic-Operator-01.jpg\" alt=\"Python Operator\" width=\"707\" height=\"370\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Arithmetic-Operator-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Arithmetic-Operator-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Arithmetic-Operator-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Arithmetic-Operator-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Arithmetic-Operator-01-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Arithmetic-Operator-01-520x272.jpg 520w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/a><p id=\"caption-attachment-42918\" class=\"wp-caption-text\">Arithmetic Operators in Python<\/p><\/div>\n<h4>a. Addition(+)<\/h4>\n<p>Adds the values on either side of the operator.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3+4<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">7<\/div>\n<p style=\"text-align: center\"><em><strong><span style=\"color: #ff0000\">CHECK YOUR KNOWLEDGE &#8211;<\/span> <span style=\"color: #ff6600\">How to use + Operator for concatenation?<\/span><\/strong><\/em><\/p>\n<p style=\"text-align: center\"><span style=\"color: #ff6600\"><em><strong>Comment, if you know the answer, else check the article &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/best-python-interview-questions\/\">Frequently asked Python Interview Questions<\/a><\/strong><\/em><\/span><\/p>\n<h4>b. Subtraction(-)<\/h4>\n<p>Subtracts the value on the right from the one on the left.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3-4<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">-1<\/div>\n<h4>c. Multiplication(*)<\/h4>\n<p>Multiplies the values on either side of the operator.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3*4<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">12<\/div>\n<h4>d. Division(\/)<\/h4>\n<p>Divides the value on the left by the one on the right. Notice that division results in a floating-point value.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3\/4<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">0.75<\/div>\n<h4>e. Exponentiation(**)<\/h4>\n<p>Raises the first number to the power of the second.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3**4<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">81<\/div>\n<h4>f. Floor Division(\/\/)<\/h4>\n<p>Divides and returns the integer value of the quotient. It dumps the digits after the decimal.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3\/\/4\r\n&gt;&gt;&gt; 4\/\/3<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 10\/\/3<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">3<\/div>\n<h4>g. Modulus(%)<\/h4>\n<p>Divides and returns the value of the remainder.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3%4<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">3<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 4%3<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 10%3<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 10.5%3<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1.5<\/div>\n<p>If you face any query in Python Operator with examples, ask us in the comment.<\/p>\n<h3>2. Python Relational Operator<\/h3>\n<div id=\"attachment_42925\" style=\"width: 765px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Relational-Operator-01-1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-42925\" class=\"wp-image-42925 \" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Relational-Operator-01-1.jpg\" alt=\"Python Operator\" width=\"755\" height=\"395\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Relational-Operator-01-1.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Relational-Operator-01-1-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Relational-Operator-01-1-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Relational-Operator-01-1-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Relational-Operator-01-1-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Relational-Operator-01-1-520x272.jpg 520w\" sizes=\"auto, (max-width: 755px) 100vw, 755px\" \/><\/a><p id=\"caption-attachment-42925\" class=\"wp-caption-text\">Relational Operators in Python<\/p><\/div>\n<p><strong>Relational Python Operator<\/strong> carries out the comparison between operands.<\/p>\n<p>They tell us whether an operand is greater than the other, lesser, equal, or a combination of those.<\/p>\n<h4>a. Less than(&lt;)<\/h4>\n<p>This operator checks if the value on the left of the operator is lesser than the one on the right.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3&lt;4<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h4>b. Greater than(&gt;)<\/h4>\n<p>It checks if the value on the left of the operator is greater than the one on the right.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3&gt;4<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">False<\/div>\n<h4>c. Less than or equal to(&lt;=)<\/h4>\n<p>It checks if the value on the left of the operator is lesser than or equal to the one on the right.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 7&lt;=7<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h4>d. Greater than or equal to(&gt;=)<\/h4>\n<p>It checks if the value on the left of the operator is greater than or equal to the one on the right.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 0&gt;=0<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h4>e. Equal to(= =)<\/h4>\n<p>This operator checks if the value on the left of the operator is equal to the one on the right.<\/p>\n<p>1 is equal to the Boolean value True, but 2 isn\u2019t. Also, 0 is equal to False.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3==3.0<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 1==True<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 7==True<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">False<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 0==False<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 0.5==True<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">False<\/div>\n<h4>f. Not equal to(!=)<\/h4>\n<p>It checks if the value on the left of the operator is not equal to the one on the right.<\/p>\n<p>The Python operator &lt;&gt; does the same job, but has been abandoned in Python 3.<\/p>\n<p>When the condition for a relative operator is fulfilled, it returns True. Otherwise, it returns False. You can use this return value in a further statement or expression.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 1!=1.0<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">False<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; -1&lt;&gt;-1.0<\/pre>\n<p>#This causes a syntax error<\/p>\n<h3>3. Python Assignment Operator<\/h3>\n<div id=\"attachment_42929\" style=\"width: 727px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Assignment-Operator-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-42929\" class=\"wp-image-42929 \" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Assignment-Operator-01.jpg\" alt=\"Python Operator\" width=\"717\" height=\"375\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Assignment-Operator-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Assignment-Operator-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Assignment-Operator-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Assignment-Operator-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Assignment-Operator-01-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Assignment-Operator-01-520x272.jpg 520w\" sizes=\"auto, (max-width: 717px) 100vw, 717px\" \/><\/a><p id=\"caption-attachment-42929\" class=\"wp-caption-text\">Assignment Operators in Python<\/p><\/div>\n<p>Python assignment operator assigns a value to a variable. It may manipulate the value by a factor before assigning it.<\/p>\n<p>We have 8 assignment operators- one plain, and seven for the 7 arithmetic python operators.<\/p>\n<h4>a. Assign(=)<\/h4>\n<p>Assigns a value to the expression on the left. Notice that = = is used for comparing, but = is used for assigning.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a=7\r\n&gt;&gt;&gt; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p>7<\/p>\n<h4>b. Add and Assign(+=)<\/h4>\n<p>Adds the values on either side and assigns it to the expression on the left. a+=10 is the same as a=a+10.<\/p>\n<p>The same goes for all the next assignment operators.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a+=2\r\n&gt;&gt;&gt; print(a)\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">9<\/div>\n<h4>c. Subtract and Assign(-=)<\/h4>\n<p>Subtracts the value on the right from the value on the left. Then it assigns it to the expression on the left.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a-=2\r\n&gt;&gt;&gt; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">7<\/div>\n<h4>d. Divide and Assign(\/=)<\/h4>\n<p>Divides the value on the left by the one on the right. Then it assigns it to the expression on the left.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a\/=7\r\n&gt;&gt;&gt; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1.0<\/div>\n<h4>e. Multiply and Assign(*=)<\/h4>\n<p>Multiplies the values on either sides. Then it assigns it to the expression on the left.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a*=8\r\n&gt;&gt;&gt; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">8.0<\/div>\n<p class=\"df-text-bold\" style=\"text-align: center\"><span class=\"df-text-red\">DON&#8217;T MISS!! <\/span><a href=\"https:\/\/data-flair.training\/blogs\/python-projects-with-source-code\/\">Top Python Projects with Source Code<\/a><\/p>\n<h4>f. Modulus and Assign(%=)<\/h4>\n<p>Performs modulus on the values on either side. Then it assigns it to the expression on the left.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a%=3\r\n&gt;&gt;&gt; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">2.0<\/div>\n<h4>g. Exponent and Assign(**=)<\/h4>\n<p>Performs exponentiation on the values on either side. Then assigns it to the expression on the left.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a**=5\r\n&gt;&gt;&gt; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">32.0<\/div>\n<h4>h. Floor-Divide and Assign(\/\/=)<\/h4>\n<p>Performs floor-division on the values on either side. Then assigns it to the expression on the left.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a\/\/=3\r\n&gt;&gt;&gt; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">10.0<\/div>\n<p>This is one of the important Python Operator.<\/p>\n<h3>4. Python Logical Operator<\/h3>\n<p>These are conjunctions that you can use to combine more than one condition.<\/p>\n<p>We have three Python logical operator &#8211; and, or, and not that come under python operators.<\/p>\n<div id=\"attachment_42930\" style=\"width: 736px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Logical-Operator-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-42930\" class=\"wp-image-42930 \" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Logical-Operator-01.jpg\" alt=\"Python Operator\" width=\"726\" height=\"380\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Logical-Operator-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Logical-Operator-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Logical-Operator-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Logical-Operator-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Logical-Operator-01-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Logical-Operator-01-520x272.jpg 520w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/a><p id=\"caption-attachment-42930\" class=\"wp-caption-text\">Logical Operators in Python<\/p><\/div>\n<h4>a. and Operator in Python<\/h4>\n<p>If the conditions on both sides of the operator are true, then the expression as a whole is true.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a=7&gt;7 and 2&gt;-1\r\n&gt;&gt;&gt; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">False<\/div>\n<h4>b. or Operator in Python<\/h4>\n<p>The expression is false only if both the statements around the operator are false. Otherwise, it is true.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a=7&gt;7 or 2&gt;-1\r\n&gt;&gt;&gt; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<p>&#8216;and&#8217; returns the first False value or the last value; &#8216;or&#8217; returns the first True value or the last value<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 7 and 0 or 5<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">5<\/div>\n<h4>c. not Operator in Python<\/h4>\n<p>This inverts the <strong>Boolean value<\/strong> of an expression. It converts True to False, and False to True.<\/p>\n<p>As you can see below, the Boolean value for 0 is False. So, not inverts it to True.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; a=not(0)\r\n&gt;&gt;&gt; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h3>5. Membership Python Operator<\/h3>\n<p>These operators test whether a value is a member of a <strong>sequence<\/strong>. The sequence may be a <strong>list<\/strong>, a <strong>string<\/strong>, or a <strong>tuple<\/strong>.<\/p>\n<p>We have two membership python operators- \u2018in\u2019 and \u2018not in\u2019.<\/p>\n<h4>a. in Operator<\/h4>\n<p>This checks if a value is a member of a sequence.<\/p>\n<p>In our example, we see that the string \u2018fox\u2019 does not belong to the list pets. But the string \u2018cat\u2019 belongs to it, so it returns True.<\/p>\n<p>Also, the string \u2018me\u2019 is a substring to the string \u2018disappointment\u2019. Therefore, it returns true.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; pets=[\u2018dog\u2019,\u2019cat\u2019,\u2019ferret\u2019]\r\n&gt;&gt;&gt; \u2018fox\u2019 in pets<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">False<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; \u2018cat\u2019 in pets<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; \u2018me\u2019 in \u2018disappointment\u2019<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h4>b. not in Operator in Python<strong><br \/>\n<\/strong><\/h4>\n<p>Unlike \u2018in\u2019, \u2018not in\u2019 checks if a value is not a member of a sequence.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; \u2018pot\u2019 not in \u2018disappointment\u2019<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<p>In doubt yet in any Python operator with examples? Please comment.<\/p>\n<h3>6. Python Identity Operator<\/h3>\n<p>Let us proceed towards the identity Operator Python.<\/p>\n<p>These operators test if the two operands share an identity. We have two identity operators- \u2018is\u2019 and \u2018is not\u2019.<\/p>\n<h4>a. is Operator in Python<\/h4>\n<p>If two operands have the same identity, it returns True. Otherwise, it returns False. Here, 2 is not the same as 20, so it returns False.<\/p>\n<p>Also, \u20182\u2019 and \u201c2\u201d are the same. The difference in quotes does not make them different. So, it returns True.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 2 is 20<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">False<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; \u20182\u2019 is \u201c2\u201d<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h4>b. is not Operator in Python<\/h4>\n<p>2 is a number, and \u20182\u2019 is a string. So, it returns a True to that.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 2 is not \u20182\u2019<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h3>7. Python Bitwise Operator<\/h3>\n<p>Bitwise operators dive beneath decimal numbers and work with the binary bits \u2014 the 0s and 1s inside every value. They look unusual (&amp; | ^ ~ &lt;&lt; &gt;&gt;) but behave like tiny switches. &amp; (AND) keeps only the bits that match in both numbers, while | (OR) keeps the bits that are on in either number. These tools are perfect for tasks like setting feature flags or turning sensors on and off inside hardware.<\/p>\n<div id=\"attachment_42933\" style=\"width: 742px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Bitwise-Operator-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-42933\" class=\"wp-image-42933 \" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Bitwise-Operator-01.jpg\" alt=\"Python Operator\" width=\"732\" height=\"383\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Bitwise-Operator-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Bitwise-Operator-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Bitwise-Operator-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Bitwise-Operator-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Bitwise-Operator-01-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Bitwise-Operator-01-520x272.jpg 520w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/a><p id=\"caption-attachment-42933\" class=\"wp-caption-text\">Bitwise Operators in Python<\/p><\/div>\n<p>On the operands, these operate bit by bit.<\/p>\n<h4>a. Binary AND(&amp;) Operator in Python<\/h4>\n<p>It performs a bit-by-bit AND operation on the two values. Here, binary for 2 is 10, and that for 3 is 11. &amp;-ing them results in 10, which is binary for 2.<\/p>\n<p>Similarly, &amp;-ing 011(3) and 100(4) results in 000(0).<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 2&amp;3<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">2<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3&amp;4<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">0<\/div>\n<h4>b. Binary OR(|) Operator in Python<\/h4>\n<p>It performs bit-by-bit OR on the two values. Here, OR-ing 10(2) and 11(3) results in 11(3).<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 2|3<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">3<\/div>\n<h4>c. Binary XOR(^) Operator in Python<\/h4>\n<p>It performs bit-by-bit XOR(exclusive-OR) on the two values. Here, XOR-ing 10(2) and 11(3) results in 01(1).<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 2^3<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<\/div>\n<h4>d. Binary One\u2019s Complement(~) in Python<\/h4>\n<p>It returns the one\u2019s complement of a number\u2019s binary. It flips the bits. Binary for 2 is 00000010. Its one\u2019s complement is 11111101.<\/p>\n<p>This is binary for -3. So, this results in -3. Similarly, ~1 results in -2.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt;~-3<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">2<\/div>\n<p>Again, one\u2019s complement of -3 is 2.<\/p>\n<h4>e. Binary Left-Shift(&lt;&lt;) Operator in Python<\/h4>\n<p>It shifts the value of the left operand the number of places to the left that the right operand specifies.<\/p>\n<p>Here, binary of 2 is 10. 2&lt;&lt;2 shifts it two places to the left. This results in 1000, which is binary for 8.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 2&lt;&lt;2<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">8<\/div>\n<h4>f. Binary Right-Shift(&gt;&gt;) in Python<\/h4>\n<p>It shifts the value of the left operand the number of places to the right that the right operand specifies.<\/p>\n<p>Here, binary of 3 is 11. 3&gt;&gt;2 shifts it two places to the right. This results in 00, which is binary for 0.<\/p>\n<p>Similarly, 3&gt;&gt;1 shifts it one place to the right. This results in 01, which is binary for 1.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; 3&gt;&gt;2\r\n&gt;&gt;&gt; 3&gt;&gt;1<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">1<\/div>\n<p>This was all about the Python Operator Tutorial.<\/p>\n<h3>Python Interview Questions on Python Operators<\/h3>\n<p>1. What is not operator in Python?<\/p>\n<p>2. Explain relational operators in Python?<\/p>\n<p>3. What does != Mean in Python?<\/p>\n<p>4. Explain the types of Bitwise Operators in Python<\/p>\n<p>5. Explain Floor-Divide and Assign Operator in Python<\/p>\n<h3>Conclusion<\/h3>\n<p>Finally, in this lesson, we looked at seven different classes of Python operator.<\/p>\n<p>You can mix operators in one line to get fast answers. For instance, total = price * qty + tax uses multiplication, addition, and assignment together. Python follows strict rules (called precedence) to choose which symbol runs first. When you understand these rules, your code stays correct and easy to read.<\/p>\n<p>Go ahead and practice some combinations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Python Operator tutorial, we will discuss what an operator is in the Python Programming Language. Operators help us perform different kinds of operations on values and variables in an easy way. By&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":42113,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[1108,2013,6445,8385,9288,10385,10744,11503,32731],"class_list":["post-5321","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-arithmetic-operators-in-python","tag-bitwise-operators-in-python","tag-identity-operators-in-python","tag-logical-operators-in-python","tag-operators-in-python","tag-python-basic-operators","tag-python-operators","tag-relational-operators-in-python","tag-types-of-operators-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Operator - Types of Operators in Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn Python arithmetic, relational, logical, assignment, bitwise, membership, and identity operators in Python with syntax &amp; examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-operator\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Operator - Types of Operators in Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn Python arithmetic, relational, logical, assignment, bitwise, membership, and identity operators in Python with syntax &amp; examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-operator\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-21T02:47:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-13T11:11:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Operators-2.jpg\" \/>\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\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Operator - Types of Operators in Python - DataFlair","description":"Learn Python arithmetic, relational, logical, assignment, bitwise, membership, and identity operators in Python with syntax & examples.","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:\/\/data-flair.training\/blogs\/python-operator\/","og_locale":"en_US","og_type":"article","og_title":"Python Operator - Types of Operators in Python - DataFlair","og_description":"Learn Python arithmetic, relational, logical, assignment, bitwise, membership, and identity operators in Python with syntax & examples.","og_url":"https:\/\/data-flair.training\/blogs\/python-operator\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2017-12-21T02:47:28+00:00","article_modified_time":"2026-04-13T11:11:19+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Operators-2.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-operator\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-operator\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Operator &#8211; Types of Operators in Python","datePublished":"2017-12-21T02:47:28+00:00","dateModified":"2026-04-13T11:11:19+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-operator\/"},"wordCount":1735,"commentCount":56,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-operator\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Operators-2.jpg","keywords":["arithmetic operators in python","bitwise operators in python","identity operators in python","logical operators in python","operators in python","python basic operators","python operators","relational operators in python","types of operators in python"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-operator\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-operator\/","url":"https:\/\/data-flair.training\/blogs\/python-operator\/","name":"Python Operator - Types of Operators in Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-operator\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-operator\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Operators-2.jpg","datePublished":"2017-12-21T02:47:28+00:00","dateModified":"2026-04-13T11:11:19+00:00","description":"Learn Python arithmetic, relational, logical, assignment, bitwise, membership, and identity operators in Python with syntax & examples.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-operator\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-operator\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-operator\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Operators-2.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2017\/12\/Python-Operators-2.jpg","width":1200,"height":628,"caption":"Python Operator - Types of Operators in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-operator\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Operator &#8211; Types of Operators in Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/5321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=5321"}],"version-history":[{"count":39,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/5321\/revisions"}],"predecessor-version":[{"id":147584,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/5321\/revisions\/147584"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/42113"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=5321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=5321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=5321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}