Python *ARGS & **KWARGS are awesome! 📦
Bro Code
@brocodezAbout
Coding bootcamps HATE HIM! 🗿
Latest Posts
Video Description
#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): 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: print(f"{kwargs.get('street')} {kwargs.get('apt')}") elif "pobox" in kwargs: print(f"{kwargs.get('street')}") print(f"{kwargs.get('pobox')}") else: print(f"{kwargs.get('street')}") 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")
You May Also Like
Boost Your Python Skills
AI-recommended products based on this video

Freenove Ultimate Starter Kit for BBC micro bit (V2 Included), 316-Page Detailed Tutorial, 225 Items, 44 Projects, Blocks and Python Code

Freenove Ultimate Starter Kit for BBC micro bit (V2 Included), 316-Page Detailed Tutorial, 225 Items, 44 Projects, Blocks and Python Code

10.1 Inch Touch Portable Monitor IPS Screen 1366x768P 60Hz 400 Brightness 99% sRGB HDMI USB-C Monitors Switch for Xbox PS3/4/5 Laptop Compatible with Raspberry Pi, Mini Touch Screen

ELECROW 8 Inch Portable Monitor, 1280x800 Mini HD Display with Built-in Speakers, USB Powered, Non-Touch LCD Screen for Raspberry Pi, PC, Laptop, Jetson Nano, Game Consoles

7 Inch Portable Monitor Touchscreen HD 1024x600 LED Display Dual HDMI Port Small Monitor for PC Raspberry Pi Laptop Computer Xbox PS4/5 Switch Built-in Speakers

BrosTrend 1800Mbps WiFi 6 Linux WiFi Adapter for PC and Raspberry Pi 2+, Long Range USB WiFi Dongle Linux for Ubuntu, Mint, Debian, Kubuntu, Lubuntu, Zorin, Windows 11/10, Dual Band Wireless Antenna




















