Arguments and Parameters

Python bootcamp #100DaysOfCode #myNotes

The difference between Arguments and Parameters.
Parameter = the name of the data that's passed into the function.
Argument = the actual value of the data.

Here are some examples:

Function without parameters.

def greet():
    print("Hello!")

greet() #will print Hello! 

Function with 1 parameter.
When calling the function, the parameter 'name' will be replaced
with the actual value (argument) 'Luus'

def greet(name):
    print(f"Hello {name}!")

greet("Luus") #will print: Hello Luus!

Functions with multiple parameters.
In this example the parameters are 'name' and 'location'.
Now, beware that if you do it like this, the order of the arguments must match the order of the parameters.

def greet(name, location):
    print(f"Hello {name}! What is it like in {location}?")

greet("Luus", "Paris") #will print: Hello Luus! What is it like in Paris?

If you switch the arguments in the example above, the output would be Hello Paris! How is it like in Luus? That's not what you wanted right? You can omit this by using 'keyword arguments'

Function call with keyword arguments.

greet(name="Luus", location="Paris")

Will give you the same results as:

greet(location="Paris", name="Luus")

Both will print: Hello Luus! What is it like in Paris?

Now I only wish I was in Paris... a girl can dream right?


You'll only receive email when LUUS andriessen publishes a new post

More from LUUS andriessen