IndentationError: Unindent Does Not Match Any Outer Indentation Level

Summary: The error IndentationError: unindent does not match any outer indentation level arises if you use inconsistent indentation of tabs or whitespaces for indented code blocks such as the if block and the for loop. For example, Python will throw an indentation error, if you use a for loop with four whitespace characters indentation for the first line, and one tab character indentation of the second line … Read more

ROT13 in Python – Simply Explained

Rot 13 SimpleExplanation

ROT13 is a simple encryption method. It shifts each character of the clear text string 13 positions forward in the alphabet. This Python one-liner does ROT13 encryption for you: Don’t worry if this seems confusing. We’ll explain it all in detail below! Note: the variable cleartxt refers to the string you want to encode. It … Read more

Coding Your Own Google Home and Launch Spotify in Python

Doesn’t this project sound exciting? Project Goal Project goal: code your own Google Home with Python and learn how to use speech recognition to launch Spotify and play songs! Ever wanted to code a powerful yet simple tool that is more bespoke than mainstream devices? We will learn how to implement it in Python with … Read more

How to Escape Special Characters of a Python String with a Single Backslash?

The backslash escape character ‘\’ is a special Python string character that is usually followed by an alphabetic character. For example, the tabular whitespace ‘\t’ and newline ‘\n’. In regular expressions, you can use the single escape to remove the special meaning of regex symbols. For example, to match the dot or asterisk characters ‘.’ … Read more

How to Disable Unit Tests Temporarily in Python?

Problem Formulation Say, you’ve written a number of unit tests using the unittest module in Pyhton. How can you disable specific unit tests temporarily? In other words: How to skip a unit test in Python’s unittest module? Example: Given the following three unit tests. How to disable tests 1 and 2? Method 1: Skip Test … Read more

Difference Between exit() and sys.exit() in Python

[toc] Problem: There are two similarly-named functions in Python, exit() and sys.exit(). What’s the difference between them, and when should I use one over the other? Introduction In contrast to programming languages like C, there is no main() method in Python. Thus, when we run a program in Python, we essentially execute all the code in the top-level … Read more

How to Detect Lowercase Letters in Python?

Problem Formulation Given a string s. How to get a Boolean value that indicates whether all characters in the string are lowercase? Example: Say, you ask the user for input and you want to check whether all input characters are lowercase for further processing: If the user types in ‘alice’, the function should return True … Read more