{"id":6970,"date":"2024-04-11T12:00:53","date_gmt":"2024-04-11T12:00:53","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=6970"},"modified":"2024-04-11T12:00:53","modified_gmt":"2024-04-11T12:00:53","slug":"assignment-operators-in-python","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/assignment-operators-in-python\/","title":{"rendered":"Assignment  Operators in Python"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\" id=\"rank-math-toc\"><p>Table of Contents<\/p><nav><ul><li ><a href=\"#what-are-assignment-operators\">What are Assignment Operators?<\/a><\/li><li ><a href=\"#1-what-is-assign-operator\">1. What is Assign Operator?<\/a><\/li><li ><a href=\"#2-what-is-add-and-assign\">2. What is Add and Assign<\/a><\/li><li ><a href=\"#3-what-is-subtract-and-assign\">3. What is Subtract and assign?<\/a><\/li><li ><a href=\"#4-what-is-multiply-and-assign\">4. What is Multiply and assign?<\/a><ul><li ><a href=\"#5-what-is-divide-and-assign-operator\">5. What is  Divide and assign Operator?<\/a><\/li><\/ul><\/li><li ><a href=\"#6-what-is-modulus-and-assign-operator\">6. What is Modulus and Assign Operator?<\/a><ul><li ><a href=\"#7-what-is-divide-floor-and-assign-operator\">7. What is Divide ( floor)and Assign Operator?<\/a><\/li><\/ul><\/li><li ><a href=\"#8-what-is-exponent-and-assign-operator\">8. What is  Exponent and Assign Operator?<\/a><ul><li ><a href=\"#9-what-is-bitwise-and-assign-operator\">9.What is  Bitwise and Assign Operator?<\/a><\/li><\/ul><\/li><li ><a href=\"#10-what-is-bitwise-or-and-assign-operator\">10. What is Bitwise OR and Assign Operator?<\/a><\/li><li ><a href=\"#11-what-is-bitwise-xor-and-assign-operator\">11. What is Bitwise XOR and Assign Operator?<\/a><\/li><li ><a href=\"#12-what-is-bitwise-right-shift-and-assign-operator\">12. What is Bitwise Right Shift and Assign Operator?<\/a><ul><li ><a href=\"#13-what-is-bitwise-left-shift-and-assign-operator\">13. What is Bitwise Left shift and Assign Operator?<\/a><\/li><\/ul><\/li><li ><a href=\"#conclusion\">Conclusion<\/a><\/li><li ><a href=\"#assignment-operators-in-python-fa-qs\">Assignment  Operators in Python- FAQs<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<p>Assignment Operators will work on values and variables.  They are the special symbols that hold arithmetic, logical, and bitwise computations. The value which the operator operates is referred to as the Operand.<\/p>\n\n\n\n<p>Read this article about Assignment Operators in Python<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-are-assignment-operators\">What are Assignment Operators?<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/www.skillvertex.com\/blog\/python-operators\/\" data-type=\"post\" data-id=\"6937\">assignment operator<\/a> will function to provide value to variables. The table below is about the different types of Assignment operator<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><strong><em>Operator<\/em><\/strong><\/th><th><strong><em>Description<\/em><\/strong><\/th><th><strong><em>Syntax<\/em><\/strong><\/th><\/tr><\/thead><tbody><tr><td>+=<\/td><td><strong>Add and Assign operator<\/strong> will add right side operand with left side operand,  assign to left operand <\/td><td>a+=b<\/td><\/tr><tr><td>=<\/td><td> It will assign the value of the right side of the expression to the left side operand<\/td><td>x=y+z<\/td><\/tr><tr><td>-=<\/td><td><strong>Subtract AND operator<\/strong> can  subtract the right operand from the left operand and then assign it to the left operand: True if both operands are equal<\/td><td>a -= b &nbsp;<\/td><\/tr><tr><td>*=<\/td><td><strong>Subtract AND operator<\/strong> can  subtract the right operand from the left operand and then assign it to the left operand: True if both operands are equal<\/td><td>a *= b &nbsp; &nbsp;&nbsp;<\/td><\/tr><tr><td>\/=<\/td><td><strong>Divide AND<\/strong> will divide the left operand with right operand and then assign to the left operand<\/td><td>a \/= b<\/td><\/tr><tr><td>%=<\/td><td><strong>Divide AND<\/strong> will divide the left operand with the right operand and then assign to the left operand<\/td><td>a %= b &nbsp;<\/td><\/tr><tr><td>&lt;&lt;=<br><\/td><td> It functions bitwise left on operands and will assign value to the left operand <\/td><td>a &lt;&lt;= b&nbsp;<br><\/td><\/tr><tr><td>&gt;&gt;=<br><\/td><td>This operator will perform right shift on operands  and can assign value to the left operand<\/td><td>a &gt;&gt;= b &nbsp; &nbsp;&nbsp;<br><br><\/td><\/tr><tr><td>^=<br><\/td><td>This will function the bitwise xOR operands and can assign value to the left operand <\/td><td>a ^= b &nbsp; &nbsp;<br><br><\/td><\/tr><tr><td>|=<br><\/td><td>This will function Bitwise OR operands and will provide value to the left operand.<\/td><td>a |= b &nbsp; &nbsp;<br><br><\/td><\/tr><tr><td>&amp;=<br><\/td><td>This operator will perform Bitwise  AND on operand and can provide value to the left operand<\/td><td>a&amp;=b<\/td><\/tr><tr><td>**=<br><\/td><td><strong>Exponent AND<\/strong> operator will evaluate the exponent value with the help of operands an assign value to   the left operand<\/td><td>a**=b<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Here  we have listed each of the  Assignment operators <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-what-is-assign-operator\">1. What is <strong>Assign<\/strong> Operator?<\/h2>\n\n\n\n<p> This assign operator will provide the value of the right side of the expression to the left operand.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x = y + z\n<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/www.skillvertex.com\/blog\/mern-stack-website-example\/\" data-type=\"post\" data-id=\"4269\">Example<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Assigning values using  \n# Assignment Operator \n  \na = 3\nb = 5\n  \nc = a + b \n  \n# Output \nprint(c)<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/www.skillvertex.com\/blog\/what-will-be-the-output-of-the-following-program\/\" data-type=\"post\" data-id=\"3081\">Output<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>8<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-what-is-add-and-assign\">2.<strong> What is Add and Assign<\/strong><\/h2>\n\n\n\n<p>This  Add and Assign operator will function to add the right side operand with the left side operator, and provide the result to the left operand.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<p>x += y<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a + b \na += b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/www.skillvertex.com\/blog\/what-will-be-the-output-of-the-following-program\/\" data-type=\"post\" data-id=\"3081\">Output<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>8<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-what-is-subtract-and-assign\">3. What is <strong>Subtract and assign<\/strong>?<\/h2>\n\n\n\n<p>This subtract and assign operator works to subtract the right operand from the left operand and give the result to the left operand.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x -= y\n<\/code><\/pre>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a - b \na -= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-2<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-what-is-multiply-and-assign\">4. What is <strong>Multiply and assign<\/strong>?<\/h2>\n\n\n\n<p>This Multiply and assign will function to multiply the right operand with the left operand and will provide the result in the left operand.<\/p>\n\n\n\n<p><em><strong>Syntax<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x *= y\n<\/code><\/pre>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a * b \na *= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>15<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5-what-is-divide-and-assign-operator\">5. What is  <strong>Divide and assign<\/strong> Operator?<\/h3>\n\n\n\n<p>This <a href=\"https:\/\/www.skillvertex.com\/blog\/c-library-math-h-functions\/\" data-type=\"post\" data-id=\"2596\">functions<\/a> to divide the left operand and provides results at the left operand.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x \/= y\n<\/code><\/pre>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a \/ b\na \/= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0.6<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6-what-is-modulus-and-assign-operator\">6. What is <strong>Modulus and Assign<\/strong> Operator?<\/h2>\n\n\n\n<p>This operator <a href=\"https:\/\/www.skillvertex.com\/blog\/variadic-functions-in-c\/\" data-type=\"post\" data-id=\"2561\">functions<\/a> using the modulus with the left and the right operand and provides results at the left operand.<\/p>\n\n\n\n<p><em><strong>Syntax<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x %= y\n<\/code><\/pre>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a % b \na %= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p> Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>3<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"7-what-is-divide-floor-and-assign-operator\"><strong>7. What is Divide ( floor)and Assign<\/strong> Operator?<\/h3>\n\n\n\n<p>This operator will divide the left operand with the right operand, and provide the result at the left operand.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x \/\/= y\n<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/www.skillvertex.com\/blog\/mern-stack-examples\/\" data-type=\"post\" data-id=\"4337\">Example<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a \/\/ b \na \/\/= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p><a href=\"https:\/\/www.skillvertex.com\/blog\/input-output-system-calls-in-c-create-open-close-read-write\/\" data-type=\"post\" data-id=\"3685\">Output<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8-what-is-exponent-and-assign-operator\">8. What is  <strong>Exponent and Assign<\/strong> Operator?<\/h2>\n\n\n\n<p>This operator will function to evaluate the exponent and value with the operands and, provide output in the left operand.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x **= y\n<\/code><\/pre>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a ** b \na **= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>243'\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"9-what-is-bitwise-and-assign-operator\">9.What is  <strong>Bitwise and Assign<\/strong> Operator?<\/h3>\n\n\n\n<p>This operator will function Bitwise AND on both the operand and provide the result on the left operand.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x &amp;= y\n<\/code><\/pre>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a &amp; b \na &amp;= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"10-what-is-bitwise-or-and-assign-operator\">10.<strong> What is Bitwise OR and Assign<\/strong> Operator?<\/h2>\n\n\n\n<p>This operand will function Bitwise OR on the operand, and can provide result at the left operand.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x |= y\n<\/code><\/pre>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a | b \na |= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>7<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"11-what-is-bitwise-xor-and-assign-operator\">11. What is <strong>Bitwise XOR and Assign<\/strong> Operator?<\/h2>\n\n\n\n<p>This operator will function for Bitwise XOR on the operands, and provide result at the left operand.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x ^= y\n<\/code><\/pre>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a ^ b \na ^= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>6<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"12-what-is-bitwise-right-shift-and-assign-operator\">12. What is <strong>Bitwise Right Shift and Assign<\/strong> Operator?<\/h2>\n\n\n\n<p>This operator will function by providing the Bitwise shift on the operands and giving the result at the left operand.<\/p>\n\n\n\n<p><em><strong>Syntax<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x &gt;&gt;= y\n<\/code><\/pre>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a &gt;&gt; b \na &gt;&gt;= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"13-what-is-bitwise-left-shift-and-assign-operator\">13. What is <strong>Bitwise Left shift and Assign<\/strong> Operator?<\/h3>\n\n\n\n<p> This operator will function Bitwise left shift by providing the Bitwise left shift on the operands and giving the result on the left operand.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x &lt;&lt;= y\n<\/code><\/pre>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 3\nb = 5\n  \n# a = a &lt;&lt; b \na &lt;&lt;= b \n  \n# Output \nprint(a)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>96<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>To conclude, different types of assignment operators are discussed in this.  Beginners can improve their knowledge and understand how to apply the assignment operators through reading this.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"assignment-operators-in-python-fa-qs\">Assignment  Operators in Python- FAQs<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1707388495029\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1. What is an assignment statement in Python?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. It will calculate the expression list and can provide a single resulting object  to each target list from left to right <\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1707388504596\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2. What is the compound operator in Python?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. The compound operator will do the operation of a binary operator and will save the result of the operation at the left operand.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1707388513443\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. <strong>What are the two types of assignment statements<\/strong><\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans.  Simple Assignment Statements and Reference Assignment Statements are the two types of assignment statements.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Assignment Operators will work on values and variables. They are the special symbols that hold arithmetic, logical, and bitwise computations. The value which the operator operates is referred to as the Operand. Read this article about Assignment Operators in Python What are Assignment Operators? The assignment operator will function to provide value to variables. The &#8230; <a title=\"Assignment  Operators in Python\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/assignment-operators-in-python\/\" aria-label=\"More on Assignment  Operators in Python\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":6974,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[864],"tags":[891,72,892],"class_list":["post-6970","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorial","tag-assignment-operators-in-python","tag-programming","tag-python-operator","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-33"],"_links":{"self":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/6970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/comments?post=6970"}],"version-history":[{"count":13,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/6970\/revisions"}],"predecessor-version":[{"id":8903,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/6970\/revisions\/8903"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/6974"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=6970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=6970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=6970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}