{"id":1521,"date":"2022-02-18T04:06:11","date_gmt":"2022-02-18T04:06:11","guid":{"rendered":"https:\/\/mypythonfundamentals.com\/?p=1521"},"modified":"2023-01-31T04:21:12","modified_gmt":"2023-01-31T04:21:12","slug":"python-operators","status":"publish","type":"post","link":"https:\/\/mypythonfundamentals.com\/index.php\/2022\/02\/18\/python-operators\/","title":{"rendered":"Python Operators"},"content":{"rendered":"\n<p>In Python, the following are the commonly used operators:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Arithmetic Operators:<\/strong><ul><li><strong>(addition)<\/strong> &#8211; Adds two values and returns the result.<\/li><li><strong>(subtraction) <\/strong>&#8211; Subtracts one value from another and returns the result.<\/li><li><strong>(multiplication) <\/strong>&#8211; Multiplies two values and returns the result. \/ (division) &#8211; Divides one value by another and returns the result (as a float if one of the values is a float). % (modulo) &#8211; Returns the remainder of dividing one value by another. \/\/ (floor division) &#8211; Divides one value by another and rounds down to the nearest integer. ** (exponentiation) &#8211; Raises one value to the power of another.<\/li><\/ul><\/li><li><strong>Comparison Operators:<\/strong> <ul><li><strong>== (equal to)<\/strong> &#8211; Returns True if two values are equal, and False otherwise. <\/li><li><strong>!= (not equal to)<\/strong> &#8211; Returns True if two values are not equal, and False otherwise.<\/li><li>(greater than) &#8211; Returns True if one value is greater than the other, and False otherwise. <\/li><li>&lt; (less than) &#8211; Returns True if one value is less than the other, and False otherwise. <\/li><li>= (greater than or equal to) &#8211; Returns True if one value is greater than or equal to the other, and False otherwise. <\/li><li>&lt;= (less than or equal to) &#8211; Returns True if one value is less than or equal to the other, and False otherwise.<\/li><\/ul><\/li><li>Assignment Operators: <ul><li>= (assignment) &#8211; Assigns a value to a variable. <\/li><li>+= (add and assign) &#8211; Adds a value to a variable and then assigns the result to the variable. <\/li><li>-= (subtract and assign) &#8211; Subtracts a value from a variable and then assigns the result to the variable. <\/li><li>*= (multiply and assign) &#8211; Multiplies a variable by a value and then assigns the result to the variable. <\/li><li>\/= (divide and assign) &#8211; Divides a variable by a value and then assigns the result to the variable.<\/li><li>%= (modulo and assign) &#8211; Finds the remainder of dividing a variable by a value and then assigns the result to the variable. <\/li><li>\/\/= (floor division and assign) &#8211; Divides a variable by a value and then rounds down to the nearest integer and assigns the result to the variable. <\/li><li>**= (exponentiation and assign) &#8211; Raises a variable to the power of another value and then assigns the result to the variable.<\/li><\/ul><\/li><li>Logical Operators: and &#8211; Returns True if both values are True, and False otherwise. or &#8211; Returns True if either value is True, and False otherwise. not &#8211; Negates a value; if the value is True, returns False, and if the value is False, returns True.<\/li><li>Identity Operators: is &#8211; Returns True if both values refer to the same object, and False otherwise. is not &#8211; Returns True if both values do not refer to the same object, and False otherwise.<\/li><li>Membership Operators: in &#8211; Returns True if a value is found in a specified sequence (such as a list or string), and False otherwise. not in &#8211; Returns True if a value is not found in a specified sequence, and False otherwise.<\/li><li>Bitwise Operators: &amp; (and) &#8211; Compares two values bit by bit and returns a value where each bit is set<\/li><\/ol>\n\n\n\n<p>These operators can be used to perform operations on values, compare values, assign values, and more. It&#8217;s important to understand the basic behavior of each operator and when to use them.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Python, the following are the commonly used operators: Arithmetic Operators: (addition) &#8211; Adds two values and returns the result. (subtraction) &#8211; Subtracts one value from another and returns the result. (multiplication) &#8211; Multiplies two values and returns the result. &hellip; <a href=\"https:\/\/mypythonfundamentals.com\/index.php\/2022\/02\/18\/python-operators\/\">Continued<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"redux-templates_canvas","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[23],"tags":[],"class_list":["post-1521","post","type-post","status-publish","format-standard","hentry","category-python-operators"],"_links":{"self":[{"href":"https:\/\/mypythonfundamentals.com\/index.php\/wp-json\/wp\/v2\/posts\/1521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mypythonfundamentals.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mypythonfundamentals.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mypythonfundamentals.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mypythonfundamentals.com\/index.php\/wp-json\/wp\/v2\/comments?post=1521"}],"version-history":[{"count":3,"href":"https:\/\/mypythonfundamentals.com\/index.php\/wp-json\/wp\/v2\/posts\/1521\/revisions"}],"predecessor-version":[{"id":1572,"href":"https:\/\/mypythonfundamentals.com\/index.php\/wp-json\/wp\/v2\/posts\/1521\/revisions\/1572"}],"wp:attachment":[{"href":"https:\/\/mypythonfundamentals.com\/index.php\/wp-json\/wp\/v2\/media?parent=1521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mypythonfundamentals.com\/index.php\/wp-json\/wp\/v2\/categories?post=1521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mypythonfundamentals.com\/index.php\/wp-json\/wp\/v2\/tags?post=1521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}