Example:
tuple = ("python", "includehelp", 43, 54.23)
Modulo of Tuple Elements
We are given two tuples consisting of integer elements. We need to create a Python program to find the modulo of tuple elements.
Input:
tuple1 = (4, 8, 7, 3, 9)
tuple2 = (3, 5, 2, 4, 3)
Output:
(1, 3, 1, 3, 0)
To find the solution, we will be simply iterating over both the tuples performing modulus operation i.e. tulp1 % tuple2 for each element. In python, we can perform the task in multiple ways using one of the multiple methods that are present in the function.
Method 1:
One method to solve the problem is by using the generator expression to perform the modulus operation on both the tuples by zipping the values using zip() method.
Output:
Method 2:
Another method to solve the problem is directly using the map() method for mapping the result of the mod operation on each element of the tuples.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer