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:])

🔍 What does list[12:] mean?

  • 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 to 4.

❗ 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.