Python Program To Display Powers of 2 Using Anonymous Function: In this program, you’ll learn to display powers of the integer 2 using Python anonymous function.
In the program, we have used an anonymous (lambda) function inside the map() built-in function to find the powers of 2.
Python Program To Display Powers of 2 Using Anonymous Function
# Display the powers of 2 using anonymous function terms = 10 # Uncomment code below to take input from the user # terms = int(input("How many terms? ")) # use anonymous function result = list(map(lambda x: 2 ** x, range(terms))) print("The total terms are:",terms) for i in range(terms): print("2 raised to power",i,"is",result[i])