Python *ARGS & **KWARGS are awesome! 📦

preview_player
Показать описание
#python #tutorial #course

00:00:00 intro
00:00:39 *args example 1
00:03:10 *args example 2
00:04:32 **kwargs
00:07:51 exercise
00:14:26 conclusion

# *args = allows you to pass multiple non-key arguments
# **kwargs = allows you to pass multiple keyword-arguments
# * unpacking operator

# ----- *ARGS Example 1 -----

def add(*nums):
total = 0
for num in nums:
total += num
return total

print(add(1, 2, 3, 4))

# ----- *ARGS Example 2 -----

def display_name(*args):
print(f"Hello", end=" ")
for arg in args:
print(arg, end=" ")

display_name("Dr.", "Spongebob", "Harold", "Squarepants", "III")

# ----- **KWARGS -----
def print_address(**kwargs):
print(value, end=" ")

print_address(street="123 Fake St.",
pobox="P.O Box 777",
city="Detroit",
state="MI",
zip="54321")

# ----- EXERCISE -----
def shipping_label(*args, **kwargs):
for arg in args:
print(arg, end=" ")
print()

if "apt" in kwargs:
elif "pobox" in kwargs:
else:

shipping_label("Dr.", "Spongebob", "Squarepants",
street="123 Fake St.",
pobox="PO box #1001",
city="Detroit",
state="MI",
zip="54321")
Рекомендации по теме
Комментарии
Автор

# *ARGS Example 1

def add(*nums):
total = 0
for num in nums:
total += num
return total

print(add(1, 2, 3, 4))

# *ARGS Example 2

def display_name(*args):
print(f"Hello", end=" ")
for arg in args:
print(arg, end=" ")

display_name("Dr.", "Spongebob", "Harold", "Squarepants", "III")

# **KWARGS
def print_address(**kwargs):
for value in kwargs.values():
print(value, end=" ")

print_address(street="123 Fake St.",
pobox="P.O Box 777",
city="Detroit",
state="MI",
zip="54321")

# EXERCISE
def shipping_label(*args, **kwargs):
for arg in args:
print(arg, end=" ")
print()

if "apt" in kwargs:
{kwargs.get('apt')}")
elif "pobox" in kwargs:


else:


print(f"{kwargs.get('city')}, {kwargs.get('state')} {kwargs.get('zip')}")

shipping_label("Dr.", "Spongebob", "Squarepants",
street="123 Fake St.",
pobox="PO box #1001",
city="Detroit",
state="MI",
zip="54321")

BroCodez
Автор

It's actually insane how effective you are in teaching these concept.. you're in another league dude. Please keep these coming.

photoshopdepth
Автор

Bro please don't stop the playlist of python. Every one of your python videos worth millions.

zabehullahalizadeh
Автор

By far the most explicit video on kwargs and args I've come across. Thanks so much for sharing

nonoobott
Автор

NIce actually someone is using their reach just at random to help other ppl! that's so nice!

oszi
Автор

The way you teach this stuff, even a baby can understand... thanks man. really appreciate

emmanuelsharp
Автор

the way he keeps it soo simple, understandable and even fun "Dr. Spongebob Harold Squarepants" 😂 i love it.

doJLife
Автор

You made this easy to understand. Probably the best video I’ve seen on this topic. Thank you!

ken_tx
Автор

This is the best explanation or *args & **kwargs, that I ever have heard and seen. Congratulations !!!

jankempynck
Автор

THANK YOU!! I finally understand *args and **kwargs after at least a year of studying Python. I still have immense respect for my previous instructor, but this video finally gives Me the level of understand I need to write MY own codes. Thank You again.!! Rob

robertschmidt
Автор

Great video as always, Bro Code. However, using the if statements there seems unnecessary as the get() method has a second parameter that sets a default value if the key doesn't exist.

For example:

kwargs.get('apt', '')

The default value is set as '' here which wouldn't show up as anything in the output.

RainnFTWj
Автор

Amazing explication about it. Right now I undertand it. Thanks a lot!!!

juankorsia
Автор

Quick and concise

Sniper precision

Let's get a Sqlalchemy video. Building models and using existing models etc

chriskeo
Автор

nice tutorial sir. easy to understand the explanations and the examples.

peterpitz
Автор

most complete coverage of the subject - thanks!

bid
Автор

What a great explanation! I love you Bro! You're the best. Thank you so much 🙏

MK-vuqt
Автор

Thank you Bro. Taking intro to Scripting right now, every so often the reading material DOES NOT hit the mark for me. Glad you always seem to have something about what I am stuck on, cause I for the life of me could not get what the nonsense the reading material was trying to tell me. Pretty sure I will have to keep coming back to review the video with each prompt I need to code into, but still THank you for the video.

jcdragneel
Автор

Thank you so much I really needed this, how did I miss on something this important

pankela
Автор

Your video is in totally another class !!!

d.h.y
Автор

thank you so much for these tutorials!

marymary