Example:
tuple = ("python", "includehelp", 43, 54.23)
Performing multiplication operation on Tuples
In this program, we are given two tuples. We need to create a Python program to return a tuple that contains the multiplication elements.
Input:
tuple1 = (4, 1, 7, 9) , tuple2 = (2, 4, 6, 7)
Output:
(8, 4, 1, 42, 63)
Python provides multiple ways to solve the problem and here we will see some of them working.
Method 1:
One method to solve the problem is by simply using generator expression where we will map the multiplication of the same index elements of both tuples using the zip() method can create a tuple for the resultant value.
Output:
Method 2:
Another method to solve the problem is by using the map function with mul operator as a working function. And then converting the created map to a tuple using the tuple() method.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer