{"id":73760,"date":"2023-12-01T14:28:07","date_gmt":"2023-12-01T12:28:07","guid":{"rendered":"https:\/\/codeacademy.bg\/uncategorized-bg\/operatori\/"},"modified":"2024-04-08T20:05:04","modified_gmt":"2024-04-08T17:05:04","slug":"operatori","status":"publish","type":"post","link":"https:\/\/codeacademy.bg\/en\/programirane\/operatori\/","title":{"rendered":"Programming Basics: Operators &#8211; An Understandable Explanation for Beginners"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">As a beginner programmer, it&#8217;s crucial to understand what operators in programming are and how they work. Operators are special symbols or keywords that perform various operations (actions) on data (and variables). This article will explore the different types of operators and explain their usage.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Arithmetic Operators<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Arithmetic operators are used to perform mathematical operations on numeric data. The most commonly used arithmetic operators are:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Addition (+): Performs the addition of two or more numbers.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Subtraction (-): Performs the subtraction of one number from another.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Multiplication (*): Performs the multiplication of two numbers.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Division (\/): Performs the division of one number by another.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Modulo division (%): Returns the remainder after dividing two numbers.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Example:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">python<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a = 10<\/span><\/p>\n<p><span style=\"font-weight: 400;\">b = 3<\/span><\/p>\n<p><span style=\"font-weight: 400;\">sum = a + b\u00a0 # Result: 13<\/span><\/p>\n<p><span style=\"font-weight: 400;\">difference = a &#8211; b\u00a0 # Result: 7<\/span><\/p>\n<p><span style=\"font-weight: 400;\">product = a * b\u00a0 # Result: 30<\/span><\/p>\n<p><span style=\"font-weight: 400;\">division = a \/ b\u00a0 # Result: 3.333333&#8230;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">remainder = a % b\u00a0 # Result: 1<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Comparison Operators<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Comparison operators are used to compare values and return a boolean result (true or false). The comparison operators are:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Equality (==): Checks if two values are equal.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Inequality (!=): Checks if two values are different.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Greater than (&gt;): Checks if the first value is greater than the second.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Less than (&lt;): Checks if the first value is less than the second.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Greater than or equal to (&gt;=): Checks if the first value is greater than or equal to the second.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Less than or equal to (&lt;=): Checks if the first value is less than or equal to the second.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Example:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">python<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = 5<\/span><\/p>\n<p><span style=\"font-weight: 400;\">y = 10<\/span><\/p>\n<p><span style=\"font-weight: 400;\">equal = x == y\u00a0 # Result: False<\/span><\/p>\n<p><span style=\"font-weight: 400;\">different = x != y\u00a0 # Result: True<\/span><\/p>\n<p><span style=\"font-weight: 400;\">greater = x &gt; y\u00a0 # Result: False<\/span><\/p>\n<p><span style=\"font-weight: 400;\">less = x &lt; y\u00a0 # Result: True<\/span><\/p>\n<p><span style=\"font-weight: 400;\">greater or equal = x &gt;= y\u00a0 # Result: False<\/span><\/p>\n<p><span style=\"font-weight: 400;\">less or equal = x &lt;= y\u00a0 # Result: True<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Assignment Operators<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Assignment operators are used to allocate and assign values to variables. The most common assignment operators include:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Assignment (=): Assigns a value to a variable.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Addition and assignment (+=): Adds a value to a variable and assigns it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Subtraction and assignment (-=): Subtracts a value from a variable and assigns it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Multiplication and assignment (*=): Multiplies a variable&#8217;s value and assigns it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Division and assignment (\/=): Divides a variable&#8217;s value and assigns it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Example:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">python<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x = 5<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x += 3\u00a0 # Same as x = x + 3 (Result: 8)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x -= 2\u00a0 # Same as x = x &#8211; 2 (Result: 6)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x *= 4\u00a0 # Same as x = x * 4 (Result: 24)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">x \/= 6\u00a0 # Same as x = x \/ 6 (Result: 4)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Logical Operators (For Advanced Users)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Logical operators are used to combine boolean values. They include:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">And (and): Returns true if both operands are true.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Or (or): Returns true if at least one of the operands is true.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Not (not): Changes the boolean value of the operand.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Example:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">python<\/span><\/p>\n<p><span style=\"font-weight: 400;\">true_value = True<\/span><\/p>\n<p><span style=\"font-weight: 400;\">false_value = False<\/span><\/p>\n<p><span style=\"font-weight: 400;\">result1 = true_value and false_value\u00a0 # Result: False<\/span><\/p>\n<p><span style=\"font-weight: 400;\">result2 = true_value or false_value\u00a0 # Result: True<\/span><\/p>\n<p><span style=\"font-weight: 400;\">result3 = not true_value\u00a0 # Result: False<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bitwise Operators (For Advanced Users)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Bitwise operators are used to manipulate bits in binary numbers. They include operators like &#8220;And&#8221; (&amp;), &#8220;Or&#8221; (|), &#8220;Xor&#8221; (^), &#8220;Left Shift&#8221; (&lt;&lt;), and &#8220;Right Shift&#8221; (&gt;&gt;).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Example:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">python<\/span><\/p>\n<p><span style=\"font-weight: 400;\">a = 5\u00a0 # Binary: 0101<\/span><\/p>\n<p><span style=\"font-weight: 400;\">b = 3\u00a0 # Binary: 0011<\/span><\/p>\n<p><span style=\"font-weight: 400;\">result1 = a &amp; b\u00a0 # Result: 0001 (Decimal 1)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">result2 = a | b\u00a0 # Result: 0111 (Decimal 7)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">result3 = a ^ b\u00a0 # Result: 0110 (Decimal 6)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">result4 = a &lt;&lt; 2\u00a0 # Result: 10100 (Decimal 20)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">result5 = a &gt;&gt; 1\u00a0 # Result: 0010 (Decimal 2)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Operators are a fundamental element in programming and allow you to perform various operations on data. Understanding the different types of operators and their usage is a key step towards becoming a programmer. I hope this article helped you understand the basic operators in programming.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a beginner programmer, it&#8217;s crucial to understand what operators in programming are and how they work. Operators are special symbols or keywords that perform various operations (actions) on data (and variables). This article will explore the different types of operators and explain their usage. Arithmetic Operators Arithmetic operators are used to perform mathematical operations [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":73143,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[97,98],"tags":[],"class_list":["post-73760","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programirane","category-programirane-za-nachinaesthi","grve-entry-item","grve-blog-item"],"_links":{"self":[{"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/posts\/73760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/comments?post=73760"}],"version-history":[{"count":1,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/posts\/73760\/revisions"}],"predecessor-version":[{"id":73761,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/posts\/73760\/revisions\/73761"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/media\/73143"}],"wp:attachment":[{"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/media?parent=73760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/categories?post=73760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeacademy.bg\/en\/wp-json\/wp\/v2\/tags?post=73760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}