Skip to main content
← CoursesPython FoundationsModule 4 · Object-oriented programmingPredict: list slicing trickspredict81 / 170
💬 Discuss🧪 Playground+75 XP
Task
📝 **Task:** Predict the output of this slicing operation:\n\n\`\`\`python\nnums = [10, 20, 30, 40, 50, 60]\nprint(nums[1:-1:2])\n\`\`\`\n\nWhat list will it print? 📋 Edit the starter code below. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.

Keep going

🔮 Predict the output

Read the code carefully

# nums[1:-1:2] = items from index 1 to -1 (exclusive), step 2
# Indices: 0:10, 1:20, 2:30, 3:40, 4:50, 5:60
# Range 1 to -1 → indices 1..4 inclusive → step 2 → indices 1, 3
print([20, 40])

What will the program print? Write here:

📣 Help someone learn PythonShare this lesson with a friend — the first 15 are free, no signup.Tweet

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…