{"id":32517,"date":"2021-04-23T09:38:43","date_gmt":"2021-04-23T07:38:43","guid":{"rendered":"https:\/\/eiposgrados.com\/?p=32517"},"modified":"2021-04-23T09:50:27","modified_gmt":"2021-04-23T07:50:27","slug":"python-basic-operator-types","status":"publish","type":"post","link":"https:\/\/eiposgrados.com\/eng\/python-blog\/python-basic-operator-types\/","title":{"rendered":"Basic operators in Python"},"content":{"rendered":"<p>In the previous posts we told you the<strong> <a href=\"https:\/\/eiposgrados.com\/eng\/python-blog\/phyton-predefined-functions\/\" class=\"rank-math-link\">predefined functions<\/a> and the <a href=\"https:\/\/eiposgrados.com\/eng\/python-blog\/python-reserved-words\/\">Keywords<\/a> in python<\/strong>, this week we are going to talk about the<strong> basic operator types in Python <\/strong>and how to use each of them with some examples.<\/p>\n\n\n\n<p><strong>The operators<\/strong> They are symbols that tell the interpreter to perform a specific operation, such as arithmetic, comparison, logic, etc.<\/p>\n\n\n\n<p>In this post we are going to learn about assignment, arithmetic, relational and logical operators.<\/p>\n\n\n\n<p>We remind you that if you want to learn more about Python, we invite you to stop by our&nbsp;<a href=\"https:\/\/eiposgrados.com\/eng\/master-in-python\/\" class=\"rank-math-link\">master in Advanced Programming in Python for Big Data, Hacking and Machine Learning<\/a> in <a href=\"https:\/\/eiposgrados.com\/eng\/\" class=\"rank-math-link\">EIP<\/a> where in just 12 months, you will become a widely qualified expert.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Assignment operators<\/strong><\/h2>\n\n\n\n<p>They are the ones we use to give<strong> value to a variable<\/strong>. Normally we usually combine them with other operators to carry out an operation. It is a way of summarizing code.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Operator<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"> <strong>Description<\/strong><\/td><td><strong>Example<\/strong><\/td><\/tr><tr><td>=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Assigns the value to the variable<\/td><td>&gt;&gt;&gt; x=5; print(\u201cResult\u201d, x) &nbsp; &nbsp; &nbsp;<br>Result 5<\/td><\/tr><tr><td>+=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Add the value to the right of the equal to the variable<\/td><td>&gt;&gt;&gt; x=5; x+=2; print(\u201cResult\u201d, x)<br>Result 7<\/td><\/tr><tr><td>-=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Subtract the value to the right of the variable X<\/td><td>&gt;&gt;&gt; x=5; x-=2; print(\u201cResult\u201d, x)<br>Result 3<\/td><\/tr><tr><td>*=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Multiply the value to the right of equal to the variable<\/td><td>&gt;&gt;&gt; x=5; x*=2; print(\u201cResult\u201d, x)<br>Result 10<\/td><\/tr><tr><td>\/=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Divide the value to the right of the variable X<\/td><td>&gt;&gt;&gt; x=5; x\/=2; print(\u201cResult\u201d, x)<br>Result 2.5<\/td><\/tr><tr><td>%=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Returns the remainder of the division of the value to the right of the equal with the variable<\/td><td>&gt;&gt;&gt; x=5; x%=2; print(\u201cResult\u201d, x)<br>Result 1<\/td><\/tr><tr><td>\/\/=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Returns the quotient of the division of the value to the right of the equal with the variable<\/td><td>&gt;&gt;&gt; x=5; x\/\/=2; print(\u201cResult \u201c, x) Results 2<\/td><\/tr><tr><td>**=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Calculates the exponent to the variable X according to the value to the right of the equal<\/td><td>&gt;&gt;&gt; x=5; x**=2; print(\u201cResult\u201d, x)&nbsp;<br>Result 25<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Arithmetic operators<\/strong><\/h2>\n\n\n\n<p>They are the ones we use to make a <strong>arithmetic and mathematical operations<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Operator<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Description<\/strong><\/td><td><strong>Example<\/strong><\/td><\/tr><tr><td>+<\/td><td class=\"has-text-align-center\" data-align=\"center\">Add numeric type values<\/td><td>&gt;&gt;&gt; 5+2<br>       7<\/td><\/tr><tr><td>\u2013<\/td><td class=\"has-text-align-center\" data-align=\"center\">Subtracts numeric type values<\/td><td>&gt;&gt;&gt; 5-2<br>3<\/td><\/tr><tr><td>\u2013<\/td><td class=\"has-text-align-center\" data-align=\"center\">Assigns a negative value to a numeric data<\/td><td>&gt;&gt;&gt; -5<br>-5<\/td><\/tr><tr><td>*<\/td><td class=\"has-text-align-center\" data-align=\"center\">Multiplies numeric type values<\/td><td>&gt;&gt;&gt; 5*2<br>10<\/td><\/tr><tr><td>\/<\/td><td class=\"has-text-align-center\" data-align=\"center\">Splits numeric type values<\/td><td>&gt;&gt;&gt; 5\/2<br>2.5<\/td><\/tr><tr><td>%<\/td><td class=\"has-text-align-center\" data-align=\"center\">Returns the remainder of the division between values of type numeric<\/td><td>&gt;&gt;&gt; 5%2<br>1<\/td><\/tr><tr><td>\/\/<\/td><td class=\"has-text-align-center\" data-align=\"center\">Returns the quotient of the division between values of numeric type<\/td><td>&gt;&gt;&gt; 5\/\/2<br>2<\/td><\/tr><tr><td>**<\/td><td class=\"has-text-align-center\" data-align=\"center\">Calculates the exponent between numerical type values<\/td><td>&gt;&gt;&gt; 5**2<br>25<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Relational operators<\/strong><\/h2>\n\n\n\n<p>They are the ones we use to <strong>compare two values<\/strong>. Returns a boolean value (true or false) depending on the condition.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Operator<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Description<\/strong><\/td><td class=\"has-text-align-left\" data-align=\"left\"><strong>Example<\/strong><\/td><\/tr><tr><td>==<\/td><td class=\"has-text-align-center\" data-align=\"center\">Compare the values to see if they are the same<\/td><td class=\"has-text-align-left\" data-align=\"left\">&gt;&gt;&gt; 5==2 False<\/td><\/tr><tr><td>!=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Compare the values to see if they are different<\/td><td class=\"has-text-align-left\" data-align=\"left\">&gt;&gt;&gt; 5!=2<br>true<\/td><\/tr><tr><td>&lt;<\/td><td class=\"has-text-align-center\" data-align=\"center\">Compares that the value on the left is less than the one on the right<\/td><td class=\"has-text-align-left\" data-align=\"left\">&gt;&gt;&gt; 5&lt;2&nbsp;<br>False<\/td><\/tr><tr><td>&gt;<\/td><td class=\"has-text-align-center\" data-align=\"center\">Compares that the value on the left is greater than the one on the right<\/td><td class=\"has-text-align-left\" data-align=\"left\">&gt;&gt;&gt; 5&gt;2&nbsp;<br>true<\/td><\/tr><tr><td>&lt;=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Compares that the value on the left is less than or equal to the one on the right<\/td><td class=\"has-text-align-left\" data-align=\"left\">&gt;&gt;&gt; 5&lt;=2<br>False<\/td><\/tr><tr><td>&gt;=<\/td><td class=\"has-text-align-center\" data-align=\"center\">Compares that the value on the left is greater than or equal to the one on the right<\/td><td class=\"has-text-align-left\" data-align=\"left\">&gt;&gt;&gt; 5&gt;=2<br>true<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Logical operators<\/strong><\/h2>\n\n\n\n<p>They are the ones we use to work with boolean values.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>Operator<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Description<\/strong><\/td><td class=\"has-text-align-center\" data-align=\"center\"><strong>Example<\/strong><\/td><\/tr><tr><td>and<\/td><td class=\"has-text-align-center\" data-align=\"center\">Check that the left and right value is met<\/td><td class=\"has-text-align-center\" data-align=\"center\">&gt;&gt;&gt; True and False   <br>False<\/td><\/tr><tr><td>or<\/td><td class=\"has-text-align-center\" data-align=\"center\">Checks that the left or right value is true<\/td><td class=\"has-text-align-center\" data-align=\"center\">&gt;&gt;&gt; True or False<br>true<\/td><\/tr><tr><td>not<\/td><td class=\"has-text-align-center\" data-align=\"center\">Returns the opposite value of the boolean value<\/td><td class=\"has-text-align-center\" data-align=\"center\">&gt;&gt;&gt; not True<br>False<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Surely you knew most of them, in that case, you can always put them into practice to learn more. <\/p>","protected":false},"excerpt":{"rendered":"<p>We explain the types of basic operators in Python and detail them. Assignment operators, arithmetic, and more. Do you know them? Visit us!<\/p>","protected":false},"author":51,"featured_media":32536,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[407],"tags":[],"class_list":["post-32517","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-python"],"acf":[],"_links":{"self":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts\/32517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/users\/51"}],"replies":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/comments?post=32517"}],"version-history":[{"count":0,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts\/32517\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/media\/32536"}],"wp:attachment":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/media?parent=32517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/categories?post=32517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/tags?post=32517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}