0
0
Pythonprogramming~20 mins

Why built-in functions are useful in Python - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Built-in Functions Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
1: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))
A3
B40
CTypeError
D4
Attempts:
2 left
๐Ÿ’ก Hint
The len() function returns the number of items in a list.
โ“ Predict Output
intermediate
1: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))
A15
B5
CTypeError
D12345
Attempts:
2 left
๐Ÿ’ก Hint
sum() adds all numbers in the list.
โ“ Predict Output
advanced
1: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))
A[1, 1, 3, 4, 5]
B[5, 4, 3, 1, 1]
CTypeError
D[5, 3, 4, 1, 1]
Attempts:
2 left
๐Ÿ’ก Hint
sorted() returns a new list sorted in descending order when reverse=True.
โ“ Predict Output
advanced
1: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)
A[2, 4, 6]
B[1, 2, 3]
CTypeError
D[3, 6, 9]
Attempts:
2 left
๐Ÿ’ก Hint
map() applies the function to each item in the list.
๐Ÿง  Conceptual
expert
2: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?
ABuilt-in functions always use more memory than custom code.
BBuilt-in functions are harder to understand than custom code.
CBuilt-in functions are usually faster and tested for correctness.
DBuilt-in functions cannot be used with lists.
Attempts:
2 left
๐Ÿ’ก Hint
Think about speed and reliability.