Category Python

Subtracting years from a date in Python

Subtracting years from a date in Python

The easiest way to subtract years from a date in Python is to use the dateutil extension. Install it with pip: pip install python-dateutil The relativedelta object from the dateutil.relativedelta module allows you to subtract any number of years from…

Adding years to a date in Python

Adding years to a date in Python

The easiest way to add years to a date in Python is to use the dateutil extension. Install it with pip: pip install python-dateutil The relativedelta object from the dateutil.relativedelta module allows you to add any number of years to…

How to subtract months from a date in Python

How to subtract months from a date in Python

The easiest way to subtract months from a date in Python is to use the dateutil extension. Install it with pip: pip install python-dateutil The relativedelta object from the dateutil.relativedelta module allows you to subtract any number of months from…

Adding months to a date in Python

Adding months to a date in Python

The easiest way to add months to a date in Python is to use the dateutil extension. Install it with pip: pip install python-dateutil The relativedelta object from the dateutil.relativedelta module allows you to add any number of months to…

Python list drop duplicates

Removing duplicates from a list is a task that might happen more often than you think. Maybe you are importing a bunch of rows from a CSV file and want to make sure you only have unique values. Or you…

Python for loop increment by 2

Python for loop increment by 2

A regular for loop will increase its iteration counter by one in each iteration. But there are situations where you want to increment the iteration counter by 2. For some reason you might want to work with only even values.…

Python 1 line for loop

Instead of using the same old way of iterating through lists, we can make our code simpler by using list comprehensions, which allow us to make a 1 line for loop in Python. Basic syntax of a 1 line for…

JWT in Python

jwt in python

JWT stands for JSON Web Token, which is a standard that defines how to send JSON objects compactly. The data in a JWT can be validated at any given time since the token is digitally signed. The JWT has three…

Single Responsibility Principle (SRP) in Python

srp

If you need a refresher on Object-Oriented Programming before reading this article, here is all you need: Classes and Objects in Python Object-Oriented Programming: Encapsulation in Python Inheritance in Python Object-Oriented Programming: Polymorphism in Python The Single Responsibility Principle (SRP)…