Slicing Lists Basics in Python

What is the output of this code snippet?

 

letters = ['a', 'b', 'c', 'd']
print(len(letters[1:-1]))

 

The goal of this puzzle is to deepen your understanding of the important concept of slicing.

Yet, it turned out to be more a test of thoroughness than anything else. The majority of users can not solve this puzzle—one of the most common errors is to overlook the word len().

The built-in function len() returns the length of a sequence object such as a string or a list. In the puzzle, we return the length of the list after cutting the head and the tail. An illuminating example for lack of thoroughness which is also the major source of bugs in your code. Ask any professional programmer!


Are you a master coder?
Test your skills now!

 

Related Video

Solution

2

 

Leave a Comment

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