Question
You have a Python list of fruits and want to extract a specific sub-list using slicing. Â Complete the missing part of the code to obtain the sub-list `['banana', 'cherry']`. fruits = ['apple', 'banana', 'cherry', 'date', 'elderberry'] # Extract the sub-list ['banana', 'cherry'] selected_fruits = fruits[___] print(selected_fruits) Which of the following options correctly completes the code to produce `['banana', 'cherry']`?
Solution
In Python slicing, `[start:end]` extracts elements from the `start` index up to, but *not including*, the `end` index. Apple is at index 0. Banana is at index 1. Cherry is at index 2. date'` is at index 3. To get `'banana'` (index 1) and `'cherry'` (index 2), you need to start at index 1 and go up to (but not include) index 3. Therefore, `fruits[1:3]` is the correct slice.
More IT DBMS Questions
- HTTPS ensures which of the following?
- Examine the following Java-like code:   ```java   class Parent {     String name = "Parent";     public void display() {       Syst...
- Which of the following matches the definition given below: It is an artificial key that aims to uniquely identify each record.
- In a relational schema, which normal form eliminates transitive dependencies (i.e., non-prime attribute depends on another non-prime attribute)?
- A PL/SQL `TRIGGER` is a stored program that automatically executes in response to:
- What will re.findall(r'\d+', 'abc123def45ghi') return?Â
- A data warehouse is primarily characterized by which of the following properties?
- Which of the following is not part of the process control block (PCB)?
- Query optimization heuristic that “pushes selections down” improves:
- Which normal form ensures that every determinant is a candidate key?