- Published on
15. Start of a list in Python
- Authors
15. What would the output of this code be?
list = ['1', ‘2', '3', '4', '5']
print (list[12:])
list[12:]
mean?
🔍 What does - You're asking Python to return a slice of the list, starting from index
12
to the end. - The list only has 5 elements, so valid indices are from
0
to4
.
❗ But here’s the key:
- Slicing out-of-range does not raise an error in Python.
- Instead, it simply returns an empty list.
✅ Output:
[]
⚠️ Extra Tip:
Be careful not to name your variable list
, since it overrides the built-in list()
function. Better to use names like my_list
or numbers
.