Improve the quality of your code with these Must-Know Python Tips

In this article, you can find some tips to avoid common errors in Python3 and some insights into the Pythonic way of writing programs. We are going to talk about function default arguments, walrus operator, and formatting expressions.

1. Do not use dynamic default arguments

Sometimes you may need to use a non-static type as a default argument value. For example, let’s imagine we need to define a function that prints a given message, and we want to include information about when the function was called (a sort of log function).

from datetime import datetime
from time import sleep

def print_time(when: datetime = datetime.now()): …

Silvia Santamaria

Data Scientist

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store