mardi 29 juin 2021

What is a smart and/or pythonic approach to writing functions with constraints on function arguments?

Suppose I wanted to write a Python function in which the arguments to this function should only ever be used with e.g. lists of equal length.

Let's imagine a python-like pseudocode implementation which might look like:

 def somefunc(arg1: list, arg2: list) -> list, where len(arg1) == len(arg2): 

What is the pythonic approach to writing a function, where passing arguments which do not satisfy such constraints would result in a (run-time) error.

Aucun commentaire:

Enregistrer un commentaire