Optional Arguments in Python With *args and **kwargs

preview_player
Показать описание

An overview on Python's *args and **kwargs feature for writing functions with a variable number of arguments and/or making some parameters that a function accepts optional.

In this tutorial I also demonstrate real world applications and use cases for optional parameters.

For example, a design pattern you can use to extend the behavior of a parent class without having to replicate the full signature of its constructor in the child class.

In summary, this is how optional function and method parameters work in Python:

*args and **kwargs let you write functions with a variable number of arguments in Python.

*args collects extra positional arguments as a tuple. **kwargs collects the extra keyword arguments as a dictionary.

The actual syntax is * and **. Calling them args and kwargs is just a convention (one you should stick to).

To learn how to use the full potential of Python check out "Python Tricks: The Book" at the link below.

* * *

FREE Python Tutorials & News:
Рекомендации по теме
Комментарии
Автор

i always denied to understand args and kwargs i thought it was more complicated but after watching this video ...boom i got it very fluently

amitpant
Автор

One of the few clear, concise and efficient discussions of anything Python I've seen on YT Thanks, great job.

justgivemethetruth
Автор

How could you beat that? What an excellent presentation of *args and **kwargs that always intimidated me at first sight. This lucid video exposition can make anyone BE ABLE to USE them comfortably in their CODE with the proper choice of expressions, functions and their arguments. BRAVO, KEEP IT UP, Dan. GOD BLESS YOU!

fet
Автор

went through quite a few bad explanations of this until I found your video. You, you're the one that got me over the args/kwargs hump.Thanks gj

RC-blpm
Автор

Why does the mouse have motion blur? THAT'S SO FREAKING COOL!

_-
Автор

Seriously bro, after 3 trash videos I found this diamond. Explained very well and precise as well.

codewithkg
Автор

i'm a spanish native speaker, but speak and understand a little english, thanks to you i can understand this now.

ElianderPerez
Автор

Nice video bud, you made the piraty stuff arg, kwarg....with the parrot on my shoulder 🙂, so simple and easy to understand.

alokgupta
Автор

Thank you very much for this video :) It is helpful for me

tymothylim
Автор

Great video. Please execute more examples - both working and common pitfalls

SeaDadLife
Автор

This just how strong python is . I just recently got into learning all this decorators and generators. It's amazing how you can interact with a function without even calling it. I don't if other languages support this kind of stuff.

ryugaryuga
Автор

Hey man, great video! massive help :) One little thing, you might want to look into getting a pop filter for your mic, or maybe a better one, if you already do. I'm listening with headphones and the audio slaps are a little distracting. Otherwise real good stuff :)

Kidinabush
Автор

Really nice, waiting for pytest session

panditnandlalpatherwali
Автор

Can't we use "list" as a formal parameters instead of "Variable Arguments"

entertainclips
Автор

HI BROTHER, dint get the wrapper thing in ur explanations, can u pls make a video on wrapping the functions or modifying as u showed in 3rd example, its a genuine request .regards

AJ-sttj
Автор

1:13 Why not print args and kwargs unconditionally? Then you will see what you get when the caller doesn’t specify anything for them.

lawrencedoliveiro
Автор

I fully understand the starred expression in the "def" statement, but I'm not sure I understand why you are using starred expression in the calling (bar and super) statements.

ThomasRStevenson
Автор

I've seen videos where they talk about Python idioms, and unwritten rules of Python. Things that make programs written in Python unique. I really don't know why we wouldn't want write code that can largely be understood by programmers fluent in any of the C like languages. I'll watch the video anyway, and see what I can learn from it.

bobchannell
Автор

why we use ', ' operator while assigning EX: e, =ax.plot() or return e,

srikanthvattukuti
Автор

Does it anyone know how type args with mac keyboard, I can only see the suffix on top of the eight, that's multiple but to get a single and double args, I can't find it, help!

monsefbenrahal