What does the Double Star operator mean in Python?
Last Updated :
12 Apr, 2025
The ** (double star)operator in Python is used for exponentiation. It raises the number on the left to the power of the number on the right. For example:
2 ** 3 returns 8 (since 2³ = 8)
It is one of the Arithmetic Operator (Like +, -, *, **, /, //, %) in Python and is also known as Power Operator.
Precedence of Arithmetic Operators
Arithmetic operators follow the same precedence rules as in mathematics, and they are: exponential is performed first, multiplication and division are performed next ,followed by addition and subtraction.
() >> ** >> * >> / >> // >> % >> + >> -
Examples of ** (Double Star) Operator:
Example 1: As Exponentiation Operator
For numeric data types, double-asterisk (**) is defined as an Exponentiation Operator. Example:
Python
a = 2
b = 5
c = a**b
print(c)
z = 2 * (4 ** 2) + 3 * (4 ** 2 - 10)
print(z)
Explanation:
1. 2 ** 5 means 2 raised to the power 5 = 32
2. In the second expression:
- 4 ** 2 = 16
- So: 2 * 16 + 3 * (16 - 10) = 32 + 18 = 50
Example 2: As arguments in functions and methods
In a function definition, the double asterisk ** is used to define **kwargs, which allows you to pass a variable number of keyword arguments as a dictionary. While kwargs is just a naming convention, the ** is what actually enables this functionality. Example:
Python
def fun(**kwargs):
for key, val in kwargs.items():
print("{} : {}".format(key, val))
fun(n_1="Prajjwal", n_2="Kareena", n_3="Brijkant")
Outputn_1 : Prajjwal
n_2 : Kareena
n_3 : Brijkant
Explanation:
- **kwargs collects keyword arguments into a dictionary.
- Inside the function, we iterate through the dictionary and print each key-value pair.
Example 3: Unpacking Dictionary into Function Parameters
Apart from defining functions, ** is also used to pass a dictionary as keyword arguments when calling a function. It's very useful when wewant to pass dynamic data into a function.
Python
def intro(name, age, city):
print(f"My name is {name}, I'm {age} years old and I live in {city}.")
p = {
"name": "Prajjwa'",
"age": 23,
"city": "Prayagraj"
}
intro(**p)
OutputMy name is Prajjwa', I'm 23 years old and I live in Prayagraj.
Explanation: The **p syntax unpacks the dictionary and passes its key-value pairs as arguments to the intro function.
Similar Reads
Python Operators In Python programming, Operators in general are used to perform operations on values and variables. These are standard symbols used for logical and arithmetic operations. In this article, we will look into different types of Python operators. OPERATORS: These are the special symbols. Eg- + , * , /,
6 min read
Precedence and Associativity of Operators in Python In Python, operators have different levels of precedence, which determine the order in which they are evaluated. When multiple operators are present in an expression, the ones with higher precedence are evaluated first. In the case of operators with the same precedence, their associativity comes int
4 min read
Python Arithmetic Operators
Python Arithmetic Operators Python operators are fundamental for performing mathematical calculations. Arithmetic operators are symbols used to perform mathematical operations on numerical values. Arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). OperatorDescriptionS
4 min read
Difference between / vs. // operator in Python In Python, both / and // are used for division, but they behave quite differently. Let's dive into what they do and how they differ with simple examples./ Operator (True Division)The / operator performs true division.It always returns a floating-point number (even if the result is a whole number).It
2 min read
Python - Star or Asterisk operator ( * ) The asterisk (*) operator in Python is a versatile tool used in various contexts. It is commonly used for multiplication, unpacking iterables, defining variable-length arguments in functions, and more.Uses of the asterisk ( * ) operator in PythonMultiplicationIn Multiplication, we multiply two numbe
3 min read
What does the Double Star operator mean in Python? The ** (double star)operator in Python is used for exponentiation. It raises the number on the left to the power of the number on the right. For example:2 ** 3 returns 8 (since 2³ = 8)It is one of the Arithmetic Operator (Like +, -, *, **, /, //, %) in Python and is also known as Power Operator.Prec
2 min read
Division Operators in Python Division Operators allow you to divide two numbers and return a quotient, i.e., the first number or number at the left is divided by the second number or number at the right and returns the quotient. There are two types of division operators: Float divisionInteger division( Floor division)When an in
5 min read
Modulo operator (%) in Python Modulo operator (%) in Python gives the remainder when one number is divided by another. Python allows both integers and floats as operands, unlike some other languages. It follows the Euclidean division rule, meaning the remainder always has the same sign as the divisor. It is used in finding even/
4 min read
Python Logical Operators