Category Python

Higher Order Functions in Python

higher order functions

Also known as first-class functions, functions can take other functions as parameters and also return other functions. Since everything in Python is an object, we can treat functions as such. Say you have a list of car brands that is…

Mutability and Immutability in Python

Mutability and Immutability

Mutability, in the context of software, is related to the ability of a certain structure to be modified at will. You can add, remove, or simply change/update items. In short, mutable objects allow modification after their creation. Immutability, of course,…

Object-Oriented Programming: Polymorphism in Python

polymorphism

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…

The Python Debugger – PDB

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 MySQL database in Python

connect mysql 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…

Docstrings in Python

docstrings

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…