Daily Python Puzzle

Recursive Power Function: Are You Stuck With This Sololearn Code?

If you learn Python with the excellent Sololearn app, you may find yourself with this code snippet: What’s the output of this code snippet? And, most importantly, how does it work? This short guide will tell you! The code creates a function that returns x^y. It leverages the important programming concept of recursion: it calls …

Recursive Power Function: Are You Stuck With This Sololearn Code? Read More »

Why Slicing With Index Out Of Range Works In Python?

Python slicing means to access a subsequence of a sequence type using the notation [start:end]. A little-known feature of slicing is that it has robust end indices. Slicing is robust even if the end index is greater than the maximal sequence index. The slice just takes all elements up to the maximal element. If the …

Why Slicing With Index Out Of Range Works In Python? Read More »

Python String Concatenation Without ‘+’

When I first saw this, I was sure it’s a bug. Well—it’s a feature! In today’s short article, you’ll learn about a small Python trick that I call “string concatenation without +”. Let’s start with some code! Plus vs. Adjacent String Literal Concatenation There are two ways to concatenate string literals in Python: Using the …

Python String Concatenation Without ‘+’ Read More »

String Concatenation – An Interactive Guide

Python has powerful built-in capabilities for string manipulation. That’s why web companies like Google love Python—it’s a perfect fit for the text-based web. This guide shows you how to use string concatenation operators using multiple forms of education: Text Puzzle Video Exercise Ready to learn string concatenation? Let’s get started! A Textual Introduction to String …

String Concatenation – An Interactive Guide Read More »

Python Slicing Bootscamp

Slicing is one of the most popular Python features. Thus, understanding slicing is key to understand existing code bases. In this tutorial, I’m going to train your slicing skills. Ready? So, let’s go! 🔪 Watch the Video Python Slicing Read About Slicing Slicing is a Python-specific concept for accessing a range of values in sequence …

Python Slicing Bootscamp Read More »

Python Control Flow Statements

Among the ingredients that make a programming language powerful are control flow statements. The Python for loop is one such control flow statement. The if statement is another one. In this tutorial, you’ll learn about both! Python For Loop The world around us is built around repetition. The sun goes up every morning and after …

Python Control Flow Statements Read More »

How To Resolve UnboundLocalError On Local Variable When Reassigned After The First Use?

Summary: To resolve an UnboundLocalError when the local variable is reassigned after the first use, you can either use the global keyword or the nonlocal keyword. The global keyword allows you to modify the values of a global variable from within a function’s local scope while the nonlocal keyword provides similar functionality in case of …

How To Resolve UnboundLocalError On Local Variable When Reassigned After The First Use? Read More »

List Indexing

What is the output of this code snippet? 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 on only one list as core data structure. Wikipedia defines …

List Indexing Read More »