The Mockingjay, Part V
The Mockingjay, Part V
It's been too long since I did a Mockingjay post, so here, have another one.
Function Arguments
Function Arguments: A Recap
Three main types of function arguments (three most common):
- Positional arguments
- Keyword arguments
- Default arguments
Positional arguments:
Keyword arguments:
Notice that in these, the order does not matter in which you use them.
Default arguments
Here we assign default values to the arguments.
THAT MEANS THAT EVEN IF WE USE NO ARGUMENTS WHEN CALLING OUR FUNCTION - THE FUNCTION STILL GETS CALLED - AND OUR DEFAULT VALUES STILL GET DEFAULTED TO.
It says here in the Codecademy course: "While these are the most common argument types, in this lesson, we will explore what happens when we want to make our function arguments MORE FLEXIBLE by TAKING A VARYING NUMBER OF ARGUMENTS."
Variable Number of Arguments: *args
The print() function - the very first function that we learned in Python !!! - can take an unlimited number of arguments.
HOW DOES IT DO THIS?
UNPACKING OPERATOR
WHA- WHA- WHA- WHA- WHAT WHAT WHAT WHAT HOW?
The unpacking operator "ALLOWS US TO GIVE OUR FUNCTIONS A VARIABLE NUMBER OF ARGUMENTS BY PERFORMING WHAT'S KNOWN AS POSITIONAL ARGUMENT PACKING".
What in the world even is POSITIONAL ARGUMENT PACKING?
Yeah no, shut up. I want to go home and I want my mum.
"positional argument unpacking"...
Yeah no...
...
I'm still working on this
Doing some coding exercises... yeah no... it's all too much.
I took a quick break for some LINEAR ALGEBRA...
... and now back to the coding stuff.
Variable number of arguments: **kwargs
BUT FIRST OF ALL
OMG THIS MAKES SO MUCH MORE SENSE NOW - THANK YOU
THANK YOU THANK YOU - THANK YOU SO SO MUCH!!!
I came across so many of these (*args and **kwargs) while I was building Django apps! And it made no sense!!! I thought it was a Django thing!
BACK TO THE PYTHON THING
Python allows us to "DEFINE FUNCTIONS WITH UNLIMITED KEYWORD ARGUMENTS."
This is as opposed to "allowing us to accept unlimited positional arguments."
So what's the big difference here?
What are the two things I am looking at here then please?
- positional arguments
- keyword arguments.
HOLD ON A MINUTE! I COVERED THESE EARLIER TODAY! IN A PREVIOUS BLOG POST! Oh no wait it's this same blog post - whoops 😂
NOPE I DON'T GET THIS - NO, NO, NO.
It's not clicking.
Maybe I need to take a break right now. Noooo.... I was just SO in the zone.
Comments
Post a Comment