Challenge - 5 Problems
Built-in Functions Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate1:00remaining
Output of using built-in function len()
What is the output of this Python code using the built-in function
len()?Python
my_list = [10, 20, 30, 40] print(len(my_list))
Attempts:
2 left
๐ก Hint
The
len() function returns the number of items in a list.โ Incorrect
The list has 4 items, so
len(my_list) returns 4.โ Predict Output
intermediate1:00remaining
Using built-in function sum() on a list
What will this code print when using the built-in function
sum()?Python
numbers = [1, 2, 3, 4, 5] print(sum(numbers))
Attempts:
2 left
๐ก Hint
sum() adds all numbers in the list.โ Incorrect
The sum of 1+2+3+4+5 is 15, so
sum(numbers) returns 15.โ Predict Output
advanced1:30remaining
Output of sorted() with reverse=True
What is the output of this code using the built-in function
sorted() with reverse=True?Python
data = [3, 1, 4, 1, 5] print(sorted(data, reverse=True))
Attempts:
2 left
๐ก Hint
sorted() returns a new list sorted in descending order when reverse=True.โ Incorrect
The list sorted from highest to lowest is [5, 4, 3, 1, 1].
โ Predict Output
advanced1:30remaining
Output of map() with a lambda function
What does this code print when using the built-in function
map() with a lambda?Python
nums = [1, 2, 3] result = list(map(lambda x: x * 2, nums)) print(result)
Attempts:
2 left
๐ก Hint
map() applies the function to each item in the list.โ Incorrect
Each number is multiplied by 2, so the result is [2, 4, 6].
๐ง Conceptual
expert2:00remaining
Why use built-in functions instead of writing your own?
Which of these is the best reason to use Python's built-in functions rather than writing your own code for common tasks?
Attempts:
2 left
๐ก Hint
Think about speed and reliability.
โ Incorrect
Built-in functions are optimized and tested by Python developers, making them faster and more reliable than most custom code.