0% found this document useful (0 votes)
29 views2 pages

Arithmetic Operators Example

The document explains Python arithmetic operators and provides examples of their use. It defines common operators like addition, subtraction, multiplication, division, and modulus. It also includes an example Python program using the operators and the output produced.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Arithmetic Operators Example

The document explains Python arithmetic operators and provides examples of their use. It defines common operators like addition, subtraction, multiplication, division, and modulus. It also includes an example Python program using the operators and the output produced.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PYTHON ARITHMETIC OPERATORS EXAMPLE

http://www.tutorialspoint.com/python/arithmetic_operators_example.htm

Copyright tutorialspoint.com

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


Operator

Description

Example

+ Addition

Adds values on either side of the


operator.

a + b = 30

- Subtraction

Subtracts right hand operand from left


hand operand.

a b = -10

*
Multiplication

Multiplies values on either side of the


operator

a * b = 200

/ Division

Divides left hand operand by right hand


operand

b/a=2

% Modulus

Divides left hand operand by right hand


operand and returns remainder

b%a=0

** Exponent

Performs exponential power calculation on


operators

a**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.

9//2 = 4 and 9.0//2.0 = 4.0

Example
Assume variable a holds 10 and variable b holds 20, then
#!/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
Line
Line
Line
Line
Line
Line

1
2
3
4
5
6
7

Value
Value
Value
Value
Value
Value
Value

of
of
of
of
of
of
of

c
c
c
c
c
c
c

is
is
is
is
is
is
is

31
11
210
2
1
8
2

Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy