## Negative Indexing in Python

What is the output of this code snippet?   [python] x = ‘cool’ print(x[-1] + x[-2] + x[-4] + x[-3]) [/python] You can index single characters in strings using the bracket notation. The first character has index 0, the second index 1, and so on. Did you ever want to access the last element in …

## If Confusion in Python

What is the output of this code snippet?   [python] def ifConfusion(x,y): if x>y: if x-5>0: x = y if y==y+y: return "A" else: return "B" elif x+y>0: while x>y: x = x-1 while y>x: y = y-1 if x==y: return "E" else: x = 2 * x if x==y: return"F" return "G" else: if …

## Python Modulo

What is the output of this code snippet?   [python] x = 51 % 3 print(x) [/python]   When I studied computer science, the professors pushed us to learn the theory behind modulo operations and residual classes. But many of us lacked motivation. We could not see why calculating the remainder of the division, i.e., …

## Overshooting Indices in Python Slicing

What is the output of this code snippet?   [python] word = "galaxy" print(word[4:50]) [/python]   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 …

## Daily Python Puzzle: List Basics Append

What is the output of this code snippet?   [python] cubes = [1, 8, 27] cubes.append(4 ** 3) print(cubes) [/python]   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 …

## Daily Python Puzzle: The Range Function

What is the output of this code snippet?   [python] print(sum(range(0,7))) [/python]   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 …

## Daily Python Puzzle: Auto String Concatenation

What is the output of this code snippet?   [python] x = ‘py’ ‘thon’ print(x) [/python]   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. …

## Daily Python Puzzle: String Concatenation

What is the output of this code snippet?   [python] print(3 * ‘un’ + ‘ium’) [/python]   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 …

## Python Integer Division [2-Min Tutorial]

Integer division consists of two steps: Perform normal float division a / b. Round the result down to the next integer. What is the output of this code snippet? [python]x = 50 // 11print(x)[/python] When I started to learn Python 3, I used to be confused about the semantics of dividing two integers. Is the …

## Daily Python Puzzle: Slicing

What is the output of this code snippet?   [python] word = "galaxy" print(len(word[1:])) [/python]   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 …

## Basics of Boolean Logic: A Short Guide

What is the output of this code snippet?   [python] # Influential reddit users # in million karmas way_fairer = 2.7 StickleyMan = 2.3 _vargas_ = 2.3 smeeee = 1.3 a = way_fairer > StickleyMan b = StickleyMan < smeeee and a c = _vargas_ >= StickleyMan c = a and b or c and …