Python · Question 11 · Medium
What will be the output of the following Python code?
nums = list(range(10))
print(nums[8:2:-2])
- [8, 6, 4, 2]
- [2, 4, 6, 8]
- [8, 6, 4]
- []
Answer and explanation
Answer: C. [8, 6, 4]
Explanation: With a negative step the slice goes backwards from index 8 and stops before index 2: indices 8, 6, 4.
Previous: What will be the output of the following Python code? · Next: What will be the output of the following Python code?
Practise python
Try a fresh set of python questions with an explanation after every answer, free and without signing up: Python practice. Or sit a full placement mock test.
More python questions
- What will be the output of the following Python code?
- What will be the output of the following Python code?
- What will be the output of the following Python code?
- What will be the output of the following Python code?
- What will be the output of the following Python code?
- What will be the output of the following Python code?
- What will be the output of the following Python code?
- What will be the output of the following Python code?
- What will be the output of the following Python code?
- What will be the output of the following Python code?
More technical & programming practice
Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge