This article describes how to use Arithmetic Operators in Python as an example. It is a basic knowledge in Python learning. For more information, see the following table to list Arithmetic Operators supported by all Python languages. Assume that variable a holds 10 and variable B holds 20, then:
Example:
The following example shows that all Python programming languages provide Arithmetic Operators:
#! /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 the above program is executed, it will produce the following results:
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