What does these operator mean

+4 votes
I know the basic operators (+,_,*,/) but I get confuse between the complex ones such as **, ^, %, //.  What does these operators mean and for what it is used?
Apr 12, 2018 in Python by ana1504.k
• 7,910 points
1,391 views

3 answers to this question.

+3 votes
Best answer

** - Performs exponential (power) calculation on operators 

^ - Binary XOR 

% - Modulus (Divides left hand operand by right hand operand and returns remainder) 

// - divide with integral result (discard remainder) 

Consider the below example:

a=10

b=20

print(a**b)

print(a^b)

print(a%b)

print(a//b)

Output:

100000000000000000000

30

10

0
answered Apr 12, 2018 by anto.trigg4
• 3,440 points

selected Oct 12, 2018 by Omkar
+1 vote

You can find all of those operators in the Python language reference, though you'll have to scroll around a bit to find them all. As other answers have said:

  • The ** operator does exponentiation. a ** b is a raised to the b power. The same ** symbol is also used in function argument and calling notations, with a different meaning (passing and receiving arbitrary keyword arguments).
  • The ^ operator does a binary xor. a ^ b will return a value with only the bits set in a or in b but not both. This one is simple!
  • The % operator is mostly to find the modulus of two integers. a % b returns the remainder after dividing a by b. Unlike the modulus operators in some other programming languages (such as C), in Python a modulus it will have the same sign as b, rather than the same sign as a. The same operator is also used for the "old" style of string formatting, so a % b can return a string if a is a format string and b is a value (or tuple of values) which can be inserted into a.
  • The // operator does Python's version of integer division. Python's integer division is not exactly the same as the integer division offered by some other languages (like C), since it rounds towards negative infinity, rather than towards zero. Together with the modulus operator, you can say that a == (a // b)*b + (a % b). In Python 2, floor division is the default behavior when you divide two integers (using the normal division operator /). Since this can be unexpected (especially when you're not picky about what types of numbers you get as arguments to a function), Python 3 has changed to make "true" (floating point) division the norm for division that would be rounded off otherwise, and it will do "floor" division only when explicitly requested. (You can also get the new behavior in Python 2 by putting from __future__ import division at the top of your files. I strongly recommend it!)
answered Oct 12, 2018 by findingbugs
• 4,780 points
+1 vote
This is informative
answered Oct 12, 2018 by abc

reshown Nov 11 by Neelam

Related Questions In Python

0 votes
0 answers

What do these operators mean (** , ^ , %, //)? [

Other than the standard +, -, *and / operators; but what does ...READ MORE

Dec 21, 2022 in Python by erzan
• 630 points
361 views
0 votes
1 answer

What does ' -> ' mean in Python function definitions?

It's a function annotation. In more detail, Python 2.x ...READ MORE

answered May 23, 2018 in Python by charlie_brown
• 7,720 points
914 views
0 votes
1 answer

What does enumerate mean?

The enumerate() function adds a counter to ...READ MORE

answered Oct 11, 2018 in Python by SDeb
• 13,300 points
627 views
0 votes
1 answer

What does [:] mean?

It's a slicing, and what it does ...READ MORE

answered Jan 16, 2019 in Python by SDeb
• 13,300 points
2,615 views
0 votes
0 answers

what is a bitwise operator in python?

can you show some operations using bitwise ...READ MORE

Apr 8, 2019 in Python by Waseem
• 4,540 points
488 views
0 votes
0 answers

what is the logical AND operator in python?

how do i use it in a ...READ MORE

Apr 12, 2019 in Python by Waseem
• 4,540 points
514 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,442 views
+2 votes
3 answers

what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
4,885 views
+4 votes
7 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP