Overshooting Indices in Python Slicing

What is the output of this code snippet?

 

word = "galaxy"
print(word[4:50])

 

This puzzle introduces a special feature of slicing. As a recap, Python slicing means to access a subsequence of a sequence type using the notation [start:end].
We show here that slicing is robust even if the end index shoots over the maximal sequence index.
So the big take away from this puzzle is—that nothing unexpected happens if slicing overshoots sequence indices.

 


Are you a master coder?
Test your skills now!

 

Related Video

Solution

xy

 

Leave a Comment

Your email address will not be published. Required fields are marked *