{"id":272,"date":"2023-02-13T09:54:08","date_gmt":"2023-02-13T09:54:08","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/?page_id=272"},"modified":"2023-02-15T09:28:47","modified_gmt":"2023-02-15T09:28:47","slug":"operators","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-1\/operators\/","title":{"rendered":"Operators"},"content":{"rendered":"\n<p>Operators in Python are all about manipulating data. The most common operator types are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Arithmetic operators<\/li><li>Assignment operators<\/li><li>Comparison operators<\/li><li>Logical operators<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Arithmetic operators<\/h2>\n\n\n\n<p>Arithmetic operators are used to carry out common mathematical operations.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Arithmetic operator<\/td><td>Meaning<\/td><\/tr><tr><td>a + b<\/td><td>Adds the value of b to a<\/td><\/tr><tr><td>a \u2013 b<\/td><td>Subtracts the value of b from a<\/td><\/tr><tr><td>a * b<\/td><td>Multiplies a by b<\/td><\/tr><tr><td>a \/ b<\/td><td>Divides a by b<\/td><\/tr><tr><td>a ** b<\/td><td>Raises a to the power of b<\/td><\/tr><tr><td>a % b<\/td><td>Divides a by b and returns the remainder<\/td><\/tr><tr><td>a \/\/ b<\/td><td>Divides a by b and rounds down<\/td><\/tr><\/tbody><\/table><figcaption>Arithmetic operators and their meaning<\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Assignment Operators<\/h2>\n\n\n\n<p>Assignment operators are a shortcut that combine an arithmetic operator and then assign the outcome of that equation to a variable. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>total_number_of_days += days_this_week<\/code><\/pre>\n\n\n\n<p>Is the same as typing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>total_number_of_days = total_number_of_days + days_this_week<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Assignment operators<\/td><td>Meaning<\/td><\/tr><tr><td>a += b<\/td><td>a = a + b<\/td><\/tr><tr><td>a -= b<\/td><td>a = a -b<\/td><\/tr><tr><td>a *= b<\/td><td>a = a * b<\/td><\/tr><tr><td>a \/= b<\/td><td>a = a\/ b<\/td><\/tr><tr><td>a **= b<\/td><td>a = a ** b<\/td><\/tr><tr><td>a \/\/= b<\/td><td>a = a \/\/ b<\/td><\/tr><\/tbody><\/table><figcaption>Assignment operators and their meaning<\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Comparison Operators<\/h2>\n\n\n\n<p>Comparison Operators compare two variables or statements and return a Boolean True or False.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Comparison Operators<\/td><td>Meaning<\/td><\/tr><tr><td>a == b<\/td><td>True if a is equal to b<\/td><\/tr><tr><td>a != b<\/td><td>True if a is not equal to b<\/td><\/tr><tr><td>a &lt; b<\/td><td>True if a is less than b<\/td><\/tr><tr><td>a &gt; b<\/td><td>True if a is greater than b<\/td><\/tr><tr><td>a &lt;= b<\/td><td>True if a is less than or equal to b<\/td><\/tr><tr><td>a &gt;= b<\/td><td>True if a is greater than or equal to b<\/td><\/tr><\/tbody><\/table><figcaption>Comparison operators and their meaning<\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Logical Operators<\/h2>\n\n\n\n<p>Logical Operators are used to combine statements and return a Boolean True or False based on the result.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Logical operator<\/td><td>Meaning<\/td><\/tr><tr><td>a or b<\/td><td>True if either a or b is True<\/td><\/tr><tr><td>a and b<\/td><td>True only if both a and b are True<\/td><\/tr><tr><td>not a<\/td><td>True if a is False<\/td><\/tr><\/tbody><\/table><figcaption>Logical operators and their meaing<\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n<div class=\"h5p-iframe-wrapper\"><iframe id=\"h5p-iframe-1\" class=\"h5p-iframe\" data-content-id=\"1\" style=\"height:1px\" src=\"about:blank\" frameBorder=\"0\" scrolling=\"no\" title=\"Operators quiz\"><\/iframe><\/div>\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<h2 class=\"wp-block-heading\">Precedence<\/h2>\n\n\n\n<p>Precedence determines the order in which operations are carried out. An operation with a higher precedence will be calculated before a lower one.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>Highest Precedence<\/td><td>Operator<\/td><td>Symbol<\/td><\/tr><tr><td><\/td><td>Parentheses<\/td><td>()<\/td><\/tr><tr><td><\/td><td>Exponential<\/td><td>**<\/td><\/tr><tr><td><\/td><td>Multiplication, division, modulo, and floor division<\/td><td>*, \/, %, \/\/<\/td><\/tr><tr><td><\/td><td>Addition and subtraction<\/td><td>+, \u2013<\/td><\/tr><tr><td><\/td><td>Comparison operators<\/td><td>&lt;, &gt;, &lt;=, &gt;=<\/td><\/tr><tr><td><\/td><td>Equality operators<\/td><td>==, !=<\/td><\/tr><tr><td><\/td><td>Assignment operators<\/td><td>=, +=, -=, *=, \/=, %=, \/\/=, **=<\/td><\/tr><tr><td>Lowest precedence<\/td><td>Logical operators<\/td><td>or, and, not<\/td><\/tr><\/tbody><\/table><figcaption>Order of operator precedence<\/figcaption><\/figure>\n\n\n\n<p>If in any doubt, wrap the separate parts in brackets so that each operation is unaffected by the others.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>total = ((a + b) \u2013 (x * y)) \/ z<\/code><\/pre>\n\n\n\n<p class=\"nextlink\"><a href=\"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-1\/challenge-1\/\" data-type=\"page\" data-id=\"283\">Next: Challenge 1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Operators in Python are all about manipulating data. The most common operator types are: Arithmetic operators Assignment operators Comparison operators Logical operators Arithmetic operators Arithmetic operators are used to carry out common mathematical operations. Arithmetic operator Meaning a + b Adds the value of b to a a \u2013 b Subtracts the value of b&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/es\/software\/software-design-and-development\/week-1\/operators\/\">Continue reading <span class=\"screen-reader-text\">Operators<\/span><\/a><\/p>\n","protected":false},"author":5710,"featured_media":0,"parent":14,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-272","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/users\/5710"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":6,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/272\/revisions"}],"predecessor-version":[{"id":285,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/272\/revisions\/285"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/pages\/14"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/es\/software\/wp-json\/wp\/v2\/media?parent=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}