What Do These Operators Mean?



In Python, there are various types of operators used to perform specific functions, such as (**), (^), (%), and (//). The (**) operator represents exponentiation, (^) represents bitwise XOR, (%) represents the modulus operation, and (//) represents floor division. In this article, we will understand the workings of these operators.

Exponentiation Operator (**)

The exponentiation operator (**) is used to raise a number to a power. This operator works the same as the Python pow() method. In exponentiation, you need two numbers: the first is the base (the number you want to raise), and the second is the power (how many times to multiply the base by itself). The power comes after the ** symbol.

Example of Exponentiation Operator

In the example below, we have created a simple program that finds 2 raised to the power of 5, which results in 32.

# Calculate 2 raised to the power of 3
result = 2 ** 5

print("2 to the power of 5 is:", result)

Following is the output of the above program -

2 to the power of 5 is: 32

Bitwise XOR Operator (^)

The (^) represents the bitwise XOR operator in Python. The term XOR stands for exclusive OR. It means that the result of the XOR operation on two bits will be 1 if only one of the bits is 1.

Example of Bitwise XOR Operator

In the example below, the (^) operator in a^b performs a bitwise XOR, which compares each bit of a (60) and b (13) and returns 1 only if the bits are different. In this case, 60 ^ 13 results in 49.

a=60
b=13
print ("a:",a, "b:",b, "a^b:",a^b)

Following is the output of the above program -

a: 60 b: 13 a^b: 49

Modulo Operator (%)

The modulo operator is denoted by the "%" symbol in Python. It can also be called the remainder operator because it is used to return the remainder of the division of two numeric operands.

Example of Modulo Operator

In the example below, the % operator gives the remainder after dividing the first number by the second.

# Example of modulo with Positive integers
print(10 % 2)
print(34 % 5)
print(43 % 6)

Following is the output of the above program -

0
4
1

Floor Division Operator (//)

The (//) symbol represents the floor division operator in Python. This operator divides two numbers and returns the largest whole number that is less than or equal to the result.

Example of Floor Division Operator

In the example below, the (//) operator divides 10 by 4 and returns only the whole number part (ignoring the decimal), so 10 // 4 gives 2 because 4 goes into 10 two full times.

a = 10
b = 4

result = a // b

print("10 // 4 =", result)

Following is the output of the above program -

10 // 4 = 2
Updated on: 2025-04-18T14:10:06+05:30

359 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements