## 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 …

## Daily Python Puzzle: List Basics Append

What is the output of this code snippet?   cubes = [1, 8, 27] cubes.append(4 ** 3) print(cubes)   This puzzle shows how you can add a new value to the end of the list using the append() function. Before appending, the Python interpreter evaluates the expression given within the brackets. Recap that the ‘**’ …

## Daily Python Puzzle: The Range Function

What is the output of this code snippet?   print(sum(range(0,7)))   Do you know the following story of the brilliant mathematician Carl Friedrich Gauss? When 8-year old Gauss went to school, his math teacher sought a few minutes of breathing pause. He told his class to solve the problem of adding all subsequent numbers from …

## Daily Python Puzzle: Auto String Concatenation

What is the output of this code snippet?   x = 'py' 'thon' print(x)   A well-designed puzzle conveys one single point that surprises the reader. This puzzle introduces a language feature that surprised me when I first saw it. The Python interpreter automatically concatenates two strings that are next to each other. Think about …

## Daily Python Puzzle: String Concatenation

What is the output of this code snippet?   print(3 * 'un' + 'ium')   Python has powerful built-in capabilities for string manipulation. Web companies like Google love Python because it is a perfect fit for the text-based World Wide Web. The puzzle introduces two basic string manipulation operators. The ‘+’ operator concatenates two strings. …

## Daily Python Puzzle: Integer Division

What is the output of this code snippet?   x = 50 // 11 print(x)   When I started to learn Python 3, I used to be confused about the semantics of dividing two integers. Is the result a float or an integer value? The reason for my confusion was a nasty Java bug that …

## Daily Python Puzzle: Slicing

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 …

## Daily Python Puzzle: List Indexing

What is the output of this code snippet?   squares = [1, 4, 9, 16, 25] print(squares)   This puzzle introduces the simple but powerful list data structure in Python. You have to search very hard to find an algorithm that is not building upon a list. Many famous algorithms such as quicksort are based …

## Daily Python Puzzle: String Indexing

What is the output of this code snippet?   x = 'silent' print(x + x + x + x + x + x)   This puzzle introduces a powerful tool for your Python toolbox. Make sure, you feel comfortable using it because many advanced puzzles depend on it. The name of the tool is indexing. … 