Python List Concatenation: Add (+) vs INPLACE Add (+=) vs extend()

List Concatenation

A wildly popular operation you’ll find in any (non-trivial) code base is to concatenate lists—but there are multiple methods to accomplish this. Master coders will always choose the right method for the right problem. This tutorial shows you the difference between three methods to concatenate lists: Concatenate two lists with the + operator. For example, … Read more

Python Print Function [And Its SECRET Separator & End Arguments]

Everybody knows the print function in Python. It prints a string to the shell–and makes the computation of a Python program explicit to the programmer. But only few coders understand its powerful arguments to format the output. What are they? There are two little-used arguments of the print function in Python. The argument sep indicates … Read more

[Free PDF Download] Coffee Break Python – Mastery Workout

Want to boost your Python skills to the next level as an intermediate coder? Want to know how to overcome being stuck at average coding level? Do you enjoy solving puzzles? We’re excited to release a new fresh, and tough Finxter book with 99 never-seen Python puzzles. It’s the hardest one in our Coffee Break … Read more

[Top 6] What’s the Best YouTube Channel to Learn Python? Channel #1 Will Surprise You

Best YouTube Channel Python

YouTube is a great way of learning Python. But those channels top all others. In this article, you’ll find a list of the top YouTube Channels — in reverse order! Corey SchΓ€fer #6 Channel link: https://www.youtube.com/user/schafer5/ 37,444,096 channel views Channel Description: This channel is focused on creating tutorials and walkthroughs for software developers, programmers, and … Read more

Python One-Liner Webserver HTTP

Want to create your own webserver in a single line of Python code? No problem, just use this command in your shell: The terminal will tell you: To shut down your webserver, kill the Python program with CTRL+c. This works if you’ve Python 3 installed on your system. To check your version, use the command … Read more

Tilde Python Pandas DataFrame

Python’s Tilde ~n operator is the bitwise negation operator: it takes the number n as binary number and “flips” all bits 0 to 1 and 1 to 0 to obtain the complement binary number. For example, the tilde operation ~1 becomes 0 and ~0 becomes 1 and ~101 becomes 010. Read all about the Tilde … Read more

Does the Dot Regex (.) Match Whitespace Characters in Python?

Yes, the dot regex matches whitespace characters when using Python’s re module. Consider the following example: Try it yourself in our interactive Python shell (click “run”): The dot matches all characters in the string–including whitespaces. You can see that there are many whitespace characters ‘ ‘ among the matched characters. Need more info? Watch the … Read more

How to Add an Element to a Python List at an Index?

To add an element to a given Python list, you can use either of the three following methods: Use the list insert method list.insert(index, element). Use slice assignment lst[index:index] = [element] to overwrite the empty slice with a list of one element. Use list concatenation with slicing lst[:2] + [‘Alice’] + lst[2:] to create a … Read more

Python Trim String [Ultimate Guide]

You’ve probably landed on this article because you’re working on a code project with textual data that has some leading or trailing whitespaces. There’s only one question you want to be answered: How to get rid of those whitespaces? So without wasting any more of your time, let’s get to the core! How to Trim … Read more

List Comprehension in Python — A Helpful Illustrated Guide

List Comprehension

List comprehension is a compact way of creating lists. The simple formula is [expression + context]. Expression: What to do with each list element? Context: What elements to select? The context consists of an arbitrary number of for and if statements. The example [x for x in range(3)] creates the list [0, 1, 2]. Being … Read more

Matplotlib Animation – A Helpful Illustrated Guide

Photo by Gensa Hub on Unsplash

Creating animations in matplotlib is reasonably straightforward. However, it can be tricky when starting, and there is no consensus for the best way to create them. In this article, I show you a few methods you can use to make amazing animations in matplotlib. Matplotlib Animation Example The hardest thing about creating animations in matplotlib … Read more