{"id":6958,"date":"2024-04-11T12:00:12","date_gmt":"2024-04-11T12:00:12","guid":{"rendered":"https:\/\/www.skillvertex.com\/blog\/?p=6958"},"modified":"2024-04-11T12:00:12","modified_gmt":"2024-04-11T12:00:12","slug":"python-arithmetic-operators","status":"publish","type":"post","link":"https:\/\/www.skillvertex.com\/blog\/python-arithmetic-operators\/","title":{"rendered":"Python Arithmetic Operators"},"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-arithmetic-operators-in-python\">What are Arithmetic Operators in Python?<\/a><\/li><li ><a href=\"#what-are-the-7-arithmetic-operators-in-python\">What are the 7 Arithmetic Operators in Python?<\/a><\/li><li ><a href=\"#precedence-of-arithmetic-operators-in-python\">Precedence of  Arithmetic Operators in Python<\/a><\/li><li ><a href=\"#what-are-the-examples-of-python-arithmetic-operators\">What are the Examples of Python Arithmetic Operators?<\/a><ul><li ><a href=\"#a-addition-operator\">a.Addition Operator<\/a><\/li><li ><a href=\"#b-subtraction-operator\">b. Subtraction Operator<\/a><\/li><li ><a href=\"#c-multiplication-operator\">c. Multiplication Operator<\/a><\/li><li ><a href=\"#d-division-operator\">d. Division Operator<\/a><\/li><li ><a href=\"#e-modulus-operator\">e. Modulus Operator<\/a><\/li><li ><a href=\"#f-exponentiation-operator\">f. Exponentiation Operator<\/a><\/li><li ><a href=\"#g-floor-division-operator\">g. Floor Division Operator<\/a><\/li><\/ul><\/li><li ><a href=\"#conclusion\">Conclusion<\/a><\/li><li ><a href=\"#python-arithmetic-operators-fa-qs\">Python Arithmetic Operators- FAQs<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<p>Python Arithmetic operators will work on mathematical operations such as addition, subtraction, multiplication, and division. Read this article to learn more about Python Arithmetic Operators.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-are-arithmetic-operators-in-python\">What are Arithmetic Operators in Python?<\/h2>\n\n\n\n<p>Arithmetic operators are referred to as <a href=\"https:\/\/www.skillvertex.com\/blog\/operators-in-c\/\" data-type=\"post\" data-id=\"1918\">binary operators<\/a> as they will perform on the two operands. <a href=\"https:\/\/www.skillvertex.com\/blog\/python-syntax\/\" data-type=\"post\" data-id=\"6924\">Python<\/a> will offer mixed arithmetic. Hence, these two operands will be of different types. In this kind of scenario, python can widen the narrower of the operands. Thus, the integer object is referred to as narrower than the float object and the float will be narrower than the complex object.<\/p>\n\n\n\n<p>Therefore, the result of the arithmetic operation of int and float is a float. Similarly, the operation of an integer and complex object will give a complex object as the result.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-are-the-7-arithmetic-operators-in-python\">What are the 7 Arithmetic Operators in Python?<\/h2>\n\n\n\n<p>The 7<a href=\"https:\/\/www.skillvertex.com\/blog\/character-arithmetic-in-c-and-c\/\" data-type=\"post\" data-id=\"1876\"> arithmetic operators <\/a>in Python are provided below<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th><em>Operator<\/em><\/th><th><em>Description<\/em><\/th><th><em>Syntax<\/em><\/th><\/tr><\/thead><tbody><tr><th>+<\/th><th>The addition adds two operands<\/th><th>x + y<\/th><\/tr><tr><th>\u2013<\/th><th>The subtraction will subtract  two operands<\/th><th>x \u2013 y<\/th><\/tr><tr><th>*<\/th><th>Multiplication can multiply two operands<\/th><th>x * y<\/th><\/tr><tr><th>\/<\/th><th>Division (float) can divide  the first operand by the second<\/th><th>x \/ y<\/th><\/tr><tr><th>\/\/<\/th><th>Division (floor) will divide the first operand by the second<\/th><th>x \/\/ y<\/th><\/tr><tr><th>%<\/th><th>The power Exponent will return the first raised to the power second.<\/th><th>x % y<\/th><\/tr><tr><td>     **<\/td><td><strong>The power Exponent will return the first raised to the power second.<\/strong><\/td><td>x ** y<br><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"precedence-of-arithmetic-operators-in-python\">Precedence of  Arithmetic Operators in Python<\/h2>\n\n\n\n<p>Let us look into the Precedence and associativity of Python Arithmetic operators.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Operator<\/th><th>Description<\/th><th>Associativity<\/th><\/tr><\/thead><tbody><tr><td><strong>**<\/strong><\/td><td>Exponentiation Operator<\/td><td>right-to-left<\/td><\/tr><tr><td><strong>+, \u2013<\/strong><br><\/td><td>Addition and Subtraction operators<br><br><\/td><td>left-to-right<\/td><\/tr><tr><td><strong>%, *, \/, \/\/<\/strong><br><\/td><td>Modulos, Multiplication, Division, and Floor Division<br><br><\/td><td>left-to-righ<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-are-the-examples-of-python-arithmetic-operators\">What are the Examples of Python Arithmetic Operators?<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"a-addition-operator\">a.Addition Operator<\/h3>\n\n\n\n<p>+ is referred to as the addition operator and is used to add 2 values in Python Programming.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>val1 = 2\nval2 = 3\n \n# using the addition operator\nres = val1 + val2\nprint(res)<\/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>5<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"b-subtraction-operator\">b. <a href=\"https:\/\/www.skillvertex.com\/blog\/python-operators\/\" data-type=\"post\" data-id=\"6937\">Subtraction Operator<\/a><\/h3>\n\n\n\n<p>_ is denoted as the subtraction operator. It can subtract the second value from the first value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>val1 = 2\nval2 = 3\n \n# using the subtraction operator\nres = val1 - val2\nprint(res)<\/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<h3 class=\"wp-block-heading\" id=\"c-multiplication-operator\">c. <a href=\"https:\/\/www.skillvertex.com\/blog\/and-operators-in-c\/\" data-type=\"post\" data-id=\"3294\">Multiplication Operator<\/a><\/h3>\n\n\n\n<p>In Python Programming language, * is considered as the multiplication operator. It will find the product of 2 values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>val1 = 2\nval2 = 3\n \n# using the multiplication operator\nres = val1 * val2\nprint(res)<\/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<h3 class=\"wp-block-heading\" id=\"d-division-operator\">d. <a href=\"https:\/\/www.skillvertex.com\/blog\/bitwise-operators-in-c-c\/\" data-type=\"post\" data-id=\"2037\">Division Operator<\/a><\/h3>\n\n\n\n<p>\/ is referred to as the division operator in <a href=\"https:\/\/www.skillvertex.com\/blog\/how-does-a-python-interpreter-works\/\" data-type=\"post\" data-id=\"6895\">Python Programming language<\/a>. It will find the quotient where the first operand will be divided by the second.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>val1 = 3\nval2 = 2\n \n# using the division operator\nres = val1 \/ val2\nprint(res)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1.5<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e-modulus-operator\">e. Modulus Operator<\/h3>\n\n\n\n<p>% is referred to as the modulus operator in Python Programming language. It will find the remainder where the first operand will be divided by the second.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>val1 = 3\nval2 = 2\n \n# using the modulus operator\nres = val1 % val2\nprint(res)<\/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<h3 class=\"wp-block-heading\" id=\"f-exponentiation-operator\">f. <a href=\"https:\/\/www.skillvertex.com\/blog\/python-operators\/\" data-type=\"post\" data-id=\"6937\">Exponentiation Operator<\/a><\/h3>\n\n\n\n<p>In Python Programming language, ** is known as the exponentiation operator. It will raise the first operand to the power of the second.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>val1 = 2\nval2 = 3\n \n# using the exponentiation operator\nres = val1 ** val2\nprint(res)<\/code><\/pre>\n\n\n\n<p>Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>8<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"g-floor-division-operator\"><strong>g. Floor Division Operator<\/strong><\/h3>\n\n\n\n<p>\/\/ will do the floor division. It will help to find the floor of the quotient where the first operand can be divided by the second.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>val1 = 3\nval2 = 2\n \n# using the floor division\nres = val1 \/\/ val2\nprint(res)<\/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=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>To conclude, beginners can improve their skill and knowledge by learning about the Arithmetic operators. The 7 arithmetic operators and their functions are also listed in this article. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"python-arithmetic-operators-fa-qs\">Python Arithmetic Operators- 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-1707306140566\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q1. What is 3 dots in Python?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. The Python ellipsis is considered a versatile object and has a placeholder, which helps in array slicing. It can improve type hiding, and simplify indexing, and multidimensional arrays.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1707306148138\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q2. What does == mean in Python?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. = will represent the equality operator. Hence, the operator will return true only if the operands are equal.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1707306155219\" class=\"rank-math-list-item\">\n<h4 class=\"rank-math-question \">Q3. What is the M flag in Python?<\/h4>\n<div class=\"rank-math-answer \">\n\n<p>Ans. M Flag will allow us to run the<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python Arithmetic operators will work on mathematical operations such as addition, subtraction, multiplication, and division. Read this article to learn more about Python Arithmetic Operators. What are Arithmetic Operators in Python? Arithmetic operators are referred to as binary operators as they will perform on the two operands. Python will offer mixed arithmetic. Hence, these two &#8230; <a title=\"Python Arithmetic Operators\" class=\"read-more\" href=\"https:\/\/www.skillvertex.com\/blog\/python-arithmetic-operators\/\" aria-label=\"More on Python Arithmetic Operators\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":6960,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[864],"tags":[72,57,889],"class_list":["post-6958","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorial","tag-programming","tag-python","tag-python-arithmetic-operators","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\/6958","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=6958"}],"version-history":[{"count":13,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/6958\/revisions"}],"predecessor-version":[{"id":8900,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/posts\/6958\/revisions\/8900"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media\/6960"}],"wp:attachment":[{"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/media?parent=6958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/categories?post=6958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skillvertex.com\/blog\/wp-json\/wp\/v2\/tags?post=6958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}