Quick actions

cmd+k|ctrl+k

Navigation

Languages

Default Parameters and Keyword Arguments

Snippet info

Language

Python

Visibility

public

Author

fpuleano

Created

2022-02-22T15:46:29.046445Z

Updated

2022-03-03T17:27:58.272731Z

# Positional arguments are arguments that are required to be in the proper position.
# The same applies to Parameters...the parameters have to be in the proper position in relation to the arguments for the program to give us the result we want.

# Keyword arguments allow us no to have to worry about position
# example:
# Default parameter

def say_hello(name = 'Darth Vader', emoji=':('):  # name and emoji are 2 variables or parameters that we have created....
    print(f'hello {name} {emoji}')
    
#arguments...are used as the actual values we provide to a function

say_hello('Fred',  ':)') # the name and the emoji are the arguments...those are the values we provide to the function
say_hello('Carla', ':)')# parameters are used when we define the fuction, arguments are used when we call the function
say_hello('Emily', ':)')

#Keyword argument
say_hello(emoji = ':)', name = 'Steven')
say_hello() # The Fuction is being called the wrong way...empty()...but because of our Default function...Darth Vader has been established it is called.
            # Default Parameters allows us as we are defining the fuction what we want as default.

# Using Keyword arguments can be bad practice...can make your code less clean...it is better to follow the positional parameters and arguments that may already
# be in place.
INFO