What is the output of this code snippet?
word = "galaxy" print(len(word[1:]))
More than one out of four Finxter users can not solve this puzzle. There are two concepts that are novel for them: the len() function and slicing.
The len() function is a handy tool to get the length of built-in Python data types such as strings, lists, dictionaries, or tuples. Learn it once and you will have an easier life in all future coding projects.
Slicing is a Python-specific concept for accessing a range of values in sequence types such as lists or strings.
Slicing is one of the most popular Python features. Thus, understanding slicing is key to understand existing code bases. The idea of slicing is simple. Use the bracket notation to access a sequence of elements instead of only a single element. You do this via the colon notation of
[start:end]. This notation defines the start index (included) and the end index (excluded). The time you invest in mastering slicing will be repaid hundredfold during your career.
Are you a master coder?
Test your skills now!