What’s the Difference Between ‘py’ and ‘python’ in the Terminal?

Problem If you run Python in your terminal or shell, you may have realized that there are two ways to do so: using the “python” command and using the “py” command. What’s the difference? Example Say, you want to check your Python version. You can run both commands and the output is different! Here’s using … Read more

What Python Version is on Your Mac?

To check the default Python version on your macOS, use the command python –version in your terminal. In particular, use the following four steps to check the Python version on your Mac operating system. Press CMD + Space to open Spotlight. Type “terminal” and press enter. Execute command: type python –version or python -V and … Read more

The Art of Clean Code [Book Resources]

This page contains resources for my book “The Art of Clean Code” (NoStarch, 2022). You can check out the book here. Olivetti Faces Access the code in the Jupyter Notebook here: Life Expectancy Calculator Access the code in the Jupyter notebook here:

Python Print Octal Without ‘0o’

Problem Formulation If you print an octal number, Python uses the prefix ‘0o’ to indicate that it’s a number in the octal system and not in the decimal system like normal integers. However, if you already know that the output numbers are octal, you don’t necessarily need the ‘0o’ prefix. How to print oct numbers … Read more

Python Print Hex Without ‘0x’

Problem Formulation If you print a hexadecimal number, Python uses the prefix ‘0x’ to indicate that it’s a number in the hexadecimal system and not in the decimal system like normal integers. However, if you already know that the output numbers are hexadecimal, you don’t necessarily need the ‘0x’ prefix. How to print hex numbers … Read more

Python Print Binary Without ‘0b’

Problem Formulation If you print a binary number, Python uses the prefix ‘0b’ to indicate that it’s a number in the binary system and not in the decimal system like normal integers. However, if you already know that the output numbers are binary, you don’t necessarily need the ‘0b’ prefix. How to print binary numbers … Read more

Pandas Plotting Autocorrelation

A correlogram is a chart used in data analysis to check for randomness in a data set, hence the name. The less the degree of randomness, the more there is a correlation between the data. The correlogram chart highlights any potential statistical significance between data points. An autocorrelogram checks for the same degree of correlation … Read more

How to Interleave Two Strings of Variable Lengths in Python?

Half an hour ago, my friend and coauthor of the textbook “Coffee Break NumPy” asked me the following question via WhatsApp: Problem Formulation How would you solve the problem of interleaving two strings in Python: Input: String s1= “AAA” and string s2 = “BBBBB” Output: String s=”ABABABBB” Being obsessed with finding the most Pythonic way … Read more

How to Print a NumPy Array Without Brackets in Python?

Note that this tutorial concerns NumPy arrays. To learn how to print lists without brackets check out this tutorial: How to Print a List Without Brackets in Python? Problem Formulation Given a NumPy array of elements. If you print the array to the shell using print(np.array([1, 2, 3])), the output is enclosed in square brackets … Read more

How to Get Accepted By Upwork as a Freelance Coder? A Field Study

Do you want to start earning money and selling your skills as a freelance coder? Great! Being a freelance coder is an excellent opportunity in today’s marketplace. You’re getting paid to learn the programming language you love. Where else can you get such a good deal? Is Upwork for you? To share my personal experience … Read more

N-Grams in Python – How They Work

We hear more and more about natural language processing. In today’s world, the amount of text content produced is growing exponentially. In order to process a text with a machine learning model, it is important to find certain information and numerical features about the text. What Are N-Grams? N-Grams are one of the tools to … Read more