0% found this document useful (0 votes)
4 views1 page

Python Arithmetic Operators Explained

The document provides examples of Python arithmetic operations, including addition, subtraction, multiplication, division, floor division, modulus, and exponentiation. It explains the behavior of the division operators and the requirement for string concatenation. Additionally, it includes a note on type errors when mixing string and integer types in operations.

Uploaded by

vishnu200121
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)
4 views1 page

Python Arithmetic Operators Explained

The document provides examples of Python arithmetic operations, including addition, subtraction, multiplication, division, floor division, modulus, and exponentiation. It explains the behavior of the division operators and the requirement for string concatenation. Additionally, it includes a note on type errors when mixing string and integer types in operations.

Uploaded by

vishnu200121
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

Output:

1) Python [Link] or py [Link]


2) a+b= 12
3) a-b= 8
4) a*b= 20
5) a/b= 5.0
6) a//b= 5
7) a%b= 0
8) a**b= 100

Eg:

1) a = 10.5
2) b=2
3)
4) a+b= 12.5
5) a-b= 8.5
6) a*b= 21.0
7) a/b= 5.25
8) a//b= 5.0
9) a%b= 0.5
10) a**b= 110.25

Eg:
10/2==>5.0
10//2==>5
10.0/2===>5.0
10.0//2===>5.0

Note: / operator always performs floating point arithmetic. Hence it will always returns
float value.

But Floor division (//) can perform both floating point and integral arithmetic. If
arguments are int type then result is int type. If atleast one argument is float type then
result is float type.

Note:

We can use +,* operators for str type also.


If we want to use + operator for str type then compulsory both arguments should be str
type only otherwise we will get error.

1) >>> "durga"+10
2) TypeError: must be str, not int
3) >>> "durga"+"10"
4) 'durga10'

nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
2  040 – 64 51 27 86, 80 96 96 96 96, 92 46 21 21 43 | [Link]

You might also like