Object-Oriented Programming: Polymorphism in Python

This is the 4th article in a series on Object-Oriented Programming: Classes and Objects in Python Object-Oriented Programming: Encapsulation in Python Inheritance in Python Object-Oriented Programming: Polymorphism in Python Read the article about Inheritance before diving into this one. Say…

Object-Oriented Programming: Encapsulation in Python

This is the 2nd article in a series on Object-Oriented Programming: Classes and Objects in Python Object-Oriented Programming: Encapsulation in Python Inheritance in Python Object-Oriented Programming: Polymorphism in Python When we are driving a car in real life we don’t…

The Python Debugger – PDB

Bugs are an inevitable part of a programmer’s life. A bug is an error in your code that makes your program produce unexpected results. Debugging is the process of locating the source of the error and fix it. The overall…

How to connect to a PostgreSQL database in Python

To connect with a PostgreSQL database, you have to install a specific module with pip: pip install psycopg2 Then you import psycopg2 and to create a connection you call psycopg2.connect(), passing the database, user, password, host, and port. In this…

How to connect to a MySQL database in Python

To connect with a MySQL database, you have to install a specific module with pip: pip install mysql-connector-python Then you import mysql.connector and to create a connection you call mysql.connector.connect(), passing the host, user, and password. In this example we…

Virtual Environments in Python with Pipenv

pipenv is a great tool to manage virtual environments in Python. You can use pip to install it: $ pip install pipenv If you just want to start a brand new virtual environment without specifying any starting dependency, just run…

How to choose a Data Structure in Python

Python has a number of built-in Data Structures to work with, each one with its own features. Here are the reasons to choose a particular Data Structure over the other: Lists: if you need your items to be ordered, and…

Docstrings in Python

Docstrings are used to document your functions, classes, modules, and methods. A documentation is formal definition of what your function does, what it expects as arguments, and what it returns, including the types of the arguments and return. We use…

String Interpolation with f-strings in Python

If you need to concatenate a string and another type, you have to do typecasting when using the print function as explained in Type casting in Python. So to convert age to a string you make str(age) in order to…