[tdb_header_logo align_vert="content-vert-center" disable_h1="yes" svg_width="eyJwaG9uZSI6IjMwIn0=" svg_color="#ffffff" show_image="eyJwaG9uZSI6Im5vbmUifQ==" show_tagline="eyJwaG9uZSI6Im5vbmUifQ==" show_title="eyJwaG9uZSI6ImJsb2NrIn0=" show_icon="eyJwaG9uZSI6Im5vbmUifQ==" text="Study Warehouse" f_text_font_size="eyJwaG9uZSI6IjMwIn0=" text_color="#ffffff"]
[tdb_mobile_search icon_color="#ffffff" tdicon="td-icon-search" icon_size="eyJhbGwiOjIyLCJwaG9uZSI6IjIxIn0="][tdb_mobile_menu inline="yes" menu_id="" icon_color="#ffffff" icon_size="eyJhbGwiOjI3LCJwaG9uZSI6IjI5In0=" tdc_css="eyJwaG9uZSI6eyJtYXJnaW4tcmlnaHQiOiItMTYiLCJwYWRkaW5nLXRvcCI6IjIiLCJkaXNwbGF5IjoiIn0sInBob25lX21heF93aWR0aCI6NzY3fQ=="]
[tdb_header_logo align_vert="content-vert-center" svg_color="#ffffff" svg_width="eyJwb3J0cmFpdCI6IjMwIiwiYWxsIjoiMzUifQ==" show_image="none" show_tagline="none" show_title="" show_icon="none" text="Study Warehouse" show_svg="none" f_text_font_size="35" text_color="#ffffff"]
[tdb_header_search inline="yes" toggle_txt_pos="after" form_align="content-horiz-right" results_msg_align="content-horiz-center" image_floated="float_left" image_width="eyJhbGwiOiIxNSIsInBvcnRyYWl0IjoiMTQifQ==" image_size="" show_cat="none" show_btn="none" show_date="none" show_review="none" show_com="none" show_excerpt="none" show_author="none" meta_padding="eyJhbGwiOiIwIDAgMCAxNnB4IiwicG9ydHJhaXQiOiIwIDAgMCAxMnB4In0=" art_title="0" all_modules_space="eyJhbGwiOiIxNiIsInBvcnRyYWl0IjoiMTIifQ==" disable_trigger="yes" exclude_pages="yes" form_bg="rgba(0,0,0,0)" form_padding="0" form_border="0" input_placeholder="Search for Content..." tdc_css="eyJhbGwiOnsibWFyZ2luLXJpZ2h0IjoiNDAiLCJ3aWR0aCI6IjM0MCIsInotaW5kZXgiOiIxMDAwMDAwMDAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0Ijp7Im1hcmdpbi1yaWdodCI6IjMwIiwid2lkdGgiOiIzMDAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" input_bg="var(--violet)" input_border="0" btn_tdicon="td-icon-search" btn_text="" input_padding="eyJhbGwiOiIwIDE0cHggMXB4IiwicG9ydHJhaXQiOiIwIDEwcHgifQ==" btn_padding="eyJhbGwiOiIwIDE0cHgiLCJwb3J0cmFpdCI6IjAgMTBweCJ9" btn_icon_size="eyJhbGwiOiIxOCIsInBvcnRyYWl0IjoiMTYifQ==" btn_bg="rgba(0,0,0,0)" btn_bg_h="rgba(0,0,0,0)" btn_icon_color_h="#ffffff" btn_icon_color="var(--white-transparent)" f_input_font_family="308" f_input_font_size="eyJhbGwiOiIxNCIsInBvcnRyYWl0IjoiMTMifQ==" f_placeholder_font_family="308" f_placeholder_font_size="eyJhbGwiOiIxNCIsInBvcnRyYWl0IjoiMTMifQ==" btn_icon_align="-1" f_input_font_line_height="eyJhbGwiOiIyLjUiLCJwb3J0cmFpdCI6IjIuMiJ9" f_placeholder_font_line_height="eyJhbGwiOiIyLjUiLCJwb3J0cmFpdCI6IjIuMiJ9" input_radius="5" placeholder_color="var(--white-transparent)" input_color="#ffffff" el_class="td-ad-header-search" results_bg="var(--violet-2)" results_border="0" results_msg_bg="var(--violet-2)" results_msg_color="var(--white-transparent)" results_msg_color_h="var(--accent)" title_txt="#ffffff" title_txt_hover="var(--accent)" meta_info_align="center" image_height="100" image_radius="5" f_title_font_family="308" f_title_font_size="eyJhbGwiOiIxNCIsInBvcnRyYWl0IjoiMTMifQ==" f_title_font_line_height="1.5" f_title_font_weight="700" results_msg_border="1px 0 0" results_msg_border_color="var(--sep-dark)" f_results_msg_font_family="308" f_results_msg_font_size="11" results_padding="eyJhbGwiOiIyMCIsInBvcnRyYWl0IjoiMTUifQ==" sec_title_color="var(--white-transparent-2)" f_sec_title_font_family="308" f_sec_title_font_size="eyJhbGwiOiIxMyIsInBvcnRyYWl0IjoiMTIifQ==" sec_title_space="eyJhbGwiOiIxMCIsInBvcnRyYWl0IjoiOCJ9" f_sec_title_font_weight="500" f_sec_title_font_line_height="1.5" results_section_1_level="0" results_section_2_level="0" results_section_3_level="0" tax_title_color="#ffffff" tax_title_color_h="var(--accent)" f_tax_title_font_family="308" f_tax_title_font_size="eyJhbGwiOiIxNSIsInBvcnRyYWl0IjoiMTQifQ==" f_tax_title_font_line_height="1.5" tax_space="eyJwb3J0cmFpdCI6IjQifQ==" show_results=""]
[tdb_header_menu main_sub_tdicon="td-icon-down" sub_tdicon="td-icon-right-arrow" mm_align_horiz="content-horiz-center" modules_on_row_regular="20%" modules_on_row_cats="25%" image_size="td_324x400" modules_category="image" show_excerpt="none" show_com="none" show_date="none" show_author="none" mm_sub_align_horiz="content-horiz-right" mm_elem_align_horiz="content-horiz-right" menu_id="" text_color="var(--white-transparent)" f_elem_font_transform="none" elem_padd="0" elem_space="eyJhbGwiOiI0MCIsInBvcnRyYWl0IjoiMzAifQ==" f_elem_font_line_height="eyJhbGwiOiI2MnB4IiwicG9ydHJhaXQiOiI1MnB4In0=" f_elem_font_family="308" f_elem_font_weight="500" f_elem_font_size="eyJhbGwiOiIxNSIsInBvcnRyYWl0IjoiMTQifQ==" tds_menu_active1-line_width="0" tds_menu_active1-text_color_h="var(--accent)" show_subcat="yes" sub_bg_color="var(--violet-2)" sub_padd="eyJhbGwiOiIxNXB4IDIwcHgiLCJwb3J0cmFpdCI6IjEzcHggMTVweCJ9" sub_elem_padd="0" sub_elem_space="eyJhbGwiOiI2IiwicG9ydHJhaXQiOiI0In0=" sub_text_color="var(--white-transparent-2)" tds_menu_sub_active1-sub_text_color_h="var(--accent)" f_sub_elem_font_family="general_global" f_sub_elem_font_size="eyJhbGwiOiIxNCIsInBvcnRyYWl0IjoiMTMifQ==" f_sub_elem_font_line_height="1.5" sub_first_left="eyJhbGwiOiItMjAiLCJwb3J0cmFpdCI6Ii0xNSJ9" sub_border_radius="5" main_sub_icon_size="eyJhbGwiOiIxMiIsInBvcnRyYWl0IjoiMTAifQ==" main_sub_icon_align="eyJhbGwiOjAsInBvcnRyYWl0IjoiMCJ9" main_sub_icon_space="eyJhbGwiOiI4IiwicG9ydHJhaXQiOiI2In0=" sub_width="eyJhbGwiOiIyMDAiLCJwb3J0cmFpdCI6IjE2MCJ9"]
[tdb_header_menu_favorites tdicon="td-icon-heart-full" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjAiLCJkaXNwbGF5IjoiIn19" icon_color="#ffffff" icon_size="eyJhbGwiOjIxLCJwb3J0cmFpdCI6IjE5In0=" show_count="" count_bg_color="#0020f4" url="https://studywarehouse.com/favorite-applications/"]
Home Blog Python Arithmetic Operators Code Example

Python Arithmetic Operators Code Example

0

Assume variable a holds 10 and variable b holds 20, then −

OperatorDescriptionExample
+ AdditionAdds values on either side of the operator.a + b = 30
– SubtractionSubtracts right hand operand from left hand operand.a – b = -10
* MultiplicationMultiplies values on either side of the operatora * b = 200
/ DivisionDivides left hand operand by right hand operandb / a = 2
% ModulusDivides left hand operand by right hand operand and returns remainderb % a = 0
** ExponentPerforms exponential (power) calculation on operatorsa**b =10 to the power 20
//Floor Division – The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (towards negative infinity) −9//2 = 4 and 9.0//2.0 = 4.0, -11//3 = -4, -11.0//3 = -4.0

Example

Assume variable a holds 21 and variable b holds 10,

#!/usr/bin/python

a = 21
b = 10
c = 0

c = a + b
print "Line 1 - Value of c is ", c

c = a - b
print "Line 2 - Value of c is ", c 

c = a * b
print "Line 3 - Value of c is ", c 

c = a / b
print "Line 4 - Value of c is ", c 

c = a % b
print "Line 5 - Value of c is ", c

a = 2
b = 3
c = a**b 
print "Line 6 - Value of c is ", c

a = 10
b = 5
c = a//b 
print "Line 7 - Value of c is ", c

When you execute the above program, it produces the following result −

Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2
Line 5 - Value of c is 1
Line 6 - Value of c is 8
Line 7 - Value of c is 2

LEAVE A REPLY

Please enter your comment!
Please enter your name here