What are the uses of the star (*) operator in Python?

Python's star (*) operator is a built-in operator with different functionalities. How this operator works depends on its utilization in the development environment.

Let's take a look at those functionalities in detail.

Functionalities

There are three primary meanings/functionalities that this operator provides:

Multiplication

For numeric operations, the application of the star (*) operator multiplies two integers:

#integer multiplication
num1 = 5
num2 = 10
print(num1 * num2)
#decimal multiplication
num3 = 3.5
num4 = 6.5
print(num3 * num4)
#complex number multiplication
a = complex(2,3)
b = complex(3,6)
print(a*b)

The above code snippet shows that the star (*) operator applies the mathematical multiplication function to different numerical data types and caters to complex data types.

Multiple arguments

The star (*) operator in Python functions allows passing a non-finite number of parameters:

def printResult(*params):
for i in params:
print(i)
printResult(5,10,15,20,25,30)

The printResult() function in the code uses the star (*) operator to receive an unrestricted number of arguments. Similarly, we can pass an extensive series of parameters in a function using this operator without actually typing them in the function declaration statement.

Repetition

The star (*) operator allows repetition in Python. Sequences of strings, lists, tuples, and more can be repeated using this operator:

#string repetition
message = "Hello World! "
print(message * 5)
#python list repetition
numberlist =[1,2,3]
print(numberlist * 3)
#python tuple repetition
fruits = ("orange", "mango", "pineapple")
print(fruits * 2)

Strings, lists, and tuples can all be repeated using the star (*) operator in Python, making coding sequences easier to write and print.

Conclusion

The star (*) operator is one of the fundamental operators of Python. It is integral for multiplicative solutions. It is a smart alternative to loops that need to traverse a list or a tuple multiple times and functions that need multiple argument definitions.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved