DEV Community

Cover image for Let's Argue...the python way.
Elizabeth Njoroge
Elizabeth Njoroge

Posted on

Let's Argue...the python way.

When you are at a hotel and the waiter is waiting for your order, you pick something from the menu. Now when you want something extra like cheese, no onions in your food or the rarity of the meat then you say that not as a requirement but as something optional.
That is how python argument works, they are values that you call a function with.

There are 5 different ways;
1.Positional Arguments, they are matched by their positions and the first argument goes to the first parameter.

2.Keyword Arguments are matched by name and the order does not matter.

3.Default Arguments define parameters that are option and when you don't provide a value, it goes to default.

4.Variable Positional also called *args collects extra positional arguments. The *args collect all positional arguments into a tuple.

5.Keyword Variable Arguments also called **kwargs collects extra keyword arguments into a dictionary.

Conclusion

  • With Positional, the order matters.
  • With Keyword, you have to be precise.
  • With *args, shows a list of things.
  • With **kwargs, shows a dictionary.

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.