Puzzles 7 to 10
Learn about the concepts of slicing, different string manipulation operators, a new way to concatenate strings, and the difference between float division and integer division.
Puzzle 7
What is the output of the following code?
Note: Enter the output you guessed. Then, press the Run button, and your new Elo will be calculated. Don’t forget to save your Elo rating.
############################### id 336## Puzzle Elo 778## Correctly solved 72 %#############################word = "galaxy"print(len(word[1:]))
Enter the input below
Slicing
Slicing is a Python-specific concept for accessing a range of values in sequence types, such as lists or strings. It is one of the most popular Python features. Understanding slicing is one of the key requirements for understanding most existing Python codebases.
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).
Forgetting that the end index is always excluded in sequence operators is a very common source of bugs.
For the sake of completeness, quickly look into the advanced slicing notation [start:end:step]
. The only difference to the previous notation is that it allows you to specify the ...