How to check if a variable exists in Python

You can easily check if a variable exists in Python in either local or global scope. To check if a variable exists in the global scope, verify the name of the variable as a string between quotes and use the…

How to iterate over a dictionary of lists in Python

Here we have a dictionary where the values are lists. The names of the countries are the keys and the associated values are lists of car brands from the respective countries. The first for loop goes through the dictionary. The…

How to calculate the number of days between two dates in Python

To calculate the number of days between two dates, you can simply subtract them. The return will be a timedelta object. From the timedelta object, call the days property. from datetime import date first_day= date(2020,9,22) second_day = date(2020,6,3) delta_difference =…

The Python Guide For Beginners

Python has become one of the fastest-growing programming languages over the past few years. Not only it is widely used, it is also an awesome language to tackle if you want to get into the world of programming. This Python…

Dictionary Union Operators in Python

As of Python 3.9, the dict type will have two new union operators. The merge operator | and the update operator |=. The merge operator The merge operator | takes two dictionaries and returns a new one. Notice that all_brands…

Removing a Prefix or a Suffix in a String in Python

As of Python 3.9, the String type will have two new methods. You can specifically remove a prefix from a string using the removeprefix() method: >>> 'Rio de Janeiro'.removeprefix("Rio") ' de Janeiro' Or remove a suffix using the removesuffix() method:…

SQL: Syntax

SQL is not case sensitive, so you can use the keywords in uppercase like SELECT or lowercase like select, both work the same. For the sake of clarity and readability, it is advised to use the reserved keywords in uppercase,…

Puzzle Solver

A few weeks ago I sent an e-mail to my subscribers and ended it asking the following question: What’s your motivation for coding? What do you want to learn? I had many incredible replies and took my time going through…