How to make python function calls bug free (argument order agnostics)

Functions are always helpful when you are moving towards an object-oriented direction trying to make code more reusable and make more modular.

Functions are also called named blocks of code which are defined to do a certain task. Python also has. very standard syntax to follow when you are defining a method.

  1. On the first line with “def” keyword, we try to tell the interpreter that this is a function.
  2. Line number two is a docstring which used for documentation purpose. Docstrings are enclosed in triple quotes, which Python looks for when it generates documentation for the functions in your programs.
  3. And line number three is telling what this function does. There is one level of indentation after you have defined function.
  4. Line number four is to call function.

You can pass arguments to functions and while passing those arguments to a function you need to maintain an order in which your function is reading values.

But if you try to reverse this order and result would be totally unexpected which you are not looking for.

In the above case, output is wired and you are not expecting this. Sometimes it becomes difficult to remember order and it also puts you in constant doubt that if you have written correct code or not.

Let’s avoid this by using keywords in the function calls.

As in the above case after we used parameter keywords then order of arguments doesn't matter. And you are also pretty sure that you have passed correct values and there is no margin or error or bug.

Credit: Python Crash Course, 2Nd Edition: A Hands-On, Project-Based Introduction To Programming

Software engineer, Leading highly scalable product @scale of million records per day.