How to Check if a List is Empty in Python

Lists are one of the most common data types you’ll be using if you start coding with Python. One of the usual checks you may have to perform is to check if a list is empty. In this tutorial, we’ll…

How to Add Days to a Date in Python

Python provides a built-in module called datetime to manipulate dates and times. In a previous post, we say how to extract the year from a date using this module (the same logic can be used for days and months, by…

Extract the Year from a Date in Python

In a previous post, we explained how we can convert a string to a date object in Python. When you perform this action, it is often because you need to generate some kind of summary statistics, by year for instance.…

Find the Median of a List in Python

When you work with numerical list in Python, you may need to apply aggregation like finding the average. Most common operations are built-in in Python and no extra-code is needed. That being said, there is no function or method to…

How to round a number in Python

Rounding a number is a common operation we often need to carry to ensure that the value in slightly changed to ensure its readability. In this tutorial, we’ll explain how you can round a number in Python and explain some…

How to get the average of a list in Python?

If we look at the official documentation, we can realize that Python does not come with a native mean() or average() function, as it does with sum() or len(). Therefore, calculating the average of a list in Python is not…

How to convert a string to a date in Python

Python comes with the datetime library to manipulate date and times. One of the most common manipulation we want to achieve is to convert a string representing a date to a real date object. By doing so, we’d be able…

How to move a file in Python

In this tutorial, we’ll explore the different options you have at your disposal to move a file (or several files) from one location to another using simple Python code. We’ll explore two of the most used libraries for this operation:…

How to Get the Last Element of a List in Python

Getting the last element of a list is often counter-intuitive, but is sometimes needed for a logic we want to implement in Python. In this tutorial, we’ll explain the different methods you can use to extract the last element from…

How to Split String by Commas in Python

In this simple tutorial, we will see how to split a string into a list of strings using the most common delimiter: the comma. Use the split() method to split a string by commas Python comes with a built-in method…