List Slicing in Python
Level 242 keystrokes
This prints a portion of the list using slicing. nums[1:4] extracts elements from index 1 up to (but not including) index 4.
Python code
# Create a list of numbers from 0 to 51nums = [0, 1, 2, 3, 4, 5]# Slicing with [start:end] extracts a portion of the list# nums[1:4] gets elements at indices 1, 2, 3 (end is exclusive)2print(nums[1:4])Output
[1, 2, 3]
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
,× 5[× 2]× 2:× 1(× 1)× 1=× 1