Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)
edited by

Other than the standard +, -, *and / operators; but what does these mean (** , ^ , %, //) ?

>>> 9+float(2) # addition 

11.0 

>>> 9-float(2) # subtraction 

7.0 

>>> 9*float(2) # multiplication 

18.0 

>>> 9/float(2) # division 

4.5 

>>> 9**float(2) # This looks like a square, (i.e. power 2) 

81.0 

>>> 9**float(3) # So ** is equivalent to `math.pow(x,p)` ? 

729.0

How about the ^ operator?

>>> 9^int(2)# What is`^`in `x^u`,it only allows `int` for `u` 11 

>>> 9^int(3) 

10 

>>> 9^int(4) 

13 

>>> 9^int(5) 

12 

>>> 9^int(6) 

15 

>>> 9^int(7) 

14 

>>> 9^int(8) 

>>> 9^int(9) 

>>> 9^int(10)

>>> 9^int(11) 

>>> 9^int(12) 

5

% in x%m returns a normal remainder modulus, but only if m < x, why is that so? What does % do?

>>> 9%float(2) 

1.0 

>>> 9%float(3) 

0.0 

>>> 9%float(4) 

1.0 

>>> 9%float(5) 

4.0 

>>> 9%float(6) 

3.0 

>>> 9%float(7) 

2.0 

>>> 9%float(8) 

1.0 

>>> 9%float(9) 

0.0 

>>> 9%float(10) 

9.0 

>>> 9%float(11) 

9.0 

>>> 9%float(12) 

9.0

How about the // operator? what does it do?

>>> 9//float(2) 

4.0 

>>> 9//float(3) 

3.0 

>>> 9//float(4) 

2.0 

>>> 9//float(5) 

1.0 

>>> 9//float(6) 

1.0 

>>> 9//float(7) 

1.0 

>>> 9//float(8) 

1.0 

>>> 9//float(9) 

1.0 

>>> 9//float(1) 

9.0 

>>> 9//float(0.5) 

18.0

2 Answers

0 votes
by (106k points)

  1. **: exponentiation.

  2. ^: exclusive-or (bitwise)

  3. %: modulus

  4. //: divide with the integral result (discard remainder)

0 votes
by (107k points)

See for the ** symbol, you are correct that this is the power function.

For this symbol, '^' is known as the bitwise XOR. The mod symbol or '%' is the modulus operator that will help you to get the remainder of the division.

'//' is a division operator that provides an integer by discarding the remainder. This is the approved form of division using the '/' symbol in most programming languages.

For more information regarding various operators in Python, do refer to the Python certification course.

Related questions

0 votes
1 answer
asked Sep 20, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...