Foundations-of-Computer-Science practice question 4 of 15
What will the expression fam[3:6] return?
Full set: 71 questionsThe expression fam[3:6] demonstrates list slicing in Python. The syntax [start:stop] extracts a sub-list. The start index, 3, is inclusive, meaning the element at index 3 is the first one included. The stop index, 6, is exclusive, meaning the slicing stops just before index 6. Therefore, the expression returns a new list containing the elements from fam at indices 3, 4, and 5.
A. This is incorrect because the starting index in a slice is inclusive. The element at index 3 would be included.
B. This is incorrect because the stopping index in a slice is exclusive. The element at index 6 would not be included.
D. This is incorrect because a slice with a start and stop index returns a range of elements, not a single element.
1. Python Software Foundation. (2023). The Python Tutorial, 3.1.3. Lists. Python 3.11.4 documentation. Retrieved from https://docs.python.org/3/tutorial/introduction.html#lists
2. DeNero, J. (n.d.). Composing Programs, 2.4.2 Slicing. University of California, Berkeley. Based on the textbook "Structure and Interpretation of Computer Programs." Retrieved from http://composingprograms.com/pages/24-sequences.html#slicing
Keep practicing
Take the free Foundations-of-Computer-Science practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Foundations-of-Computer-Science practice questions
- Question 1What is the purpose of a parameter in a function definition?
- Question 2What is the primary purpose of an operating system?
- Question 3Which action is taken if the first number is the lowest value in a selection sort?
- Question 5What will the output be of this line?
- Question 6Which aspect is excluded from a NumPy array’s structure?
- Question 7Which of the following best defines an algorithm?
