Define all the sections of this function?
~~~
def 1______(2________):
“ 3______”
return 4______
result = name(5_______)
~~~
What are the different type of function arguments?
With regards to Functions, what are Keyword arguments?
def name_maker(first_name="Miachel", last_name= "Jackson"):
return f"{first_name} {last_name}"
print(name_maker())Can you have all default Parameter calls in Functions?
Yes, the can, they all have set arguments.
def name_maker(first_name="Stev", middle_name="Donnar", last_name="Wilson", ):
return f"{first_name} {middle_name} {last_name}"
print(name_maker())
print(name_maker("Michael", "Joseph", "Jaskson"))
print(name_maker("Jaskson", "Joseph", "Michael"))When called like this, the position matters, similar to Positional arguments:
Output:
print(name_maker()): Stev Donnar Wilson
print(name_maker(“Michael”, “Joseph”, “Jaskson”)): Michael Joseph Jaskson
print(name_maker(“Jaskson”, “Joseph”, “Michael”)): Jaskson Joseph Michael
What is the most import thing with regards to positional arguments?
The order the argument is passed, matters in functional arguments.
First name must come first, then last name.
The order of the function call must match the order of the parameters in the function definition.
See below:
~~~
def name_maker(first_name, last_name):
return f”{first_name} {last_name}”
print(name_maker(“Michael”, “Jackson”))
print(name_maker(“Jackson”, “Miachel”))
~~~
Output:
print(name_maker(“Michael”, “Jackson”))
Miachel Jackson
print(name_maker(“Jackson”, “Michael”))
Jackson Michael
What most import for calling Default values(aruguments)?
Default values(aruguments) most be the last parameter set in the Function call.
def name_maker(first_name, last_name, middle_name=”Joseph”):
What are the names for all of these function calls?
1. describe_pet(‘willie’)
2. describe_pet(pet_name=’willie’)
3. describe_pet(‘harry’, ‘hamster’)
4. describe_pet(pet_name=’harry’, animal_type=’hamster’)
5. describe_pet(animal_type=’hamster’, pet_name=’harry’)
6. describe_pet(animal_type, pet_name, size=small)
With regards to Functions, what are Default values(aruguments)?
Default values is the passed vaule os a parameter provided in a Function call. Python will use the provided value if no argument is passed in the function call.
~~~
def name_maker(first_name, last_name, middle_name=”Joseph”):
return f”{first_name} {middle_name} {last_name}”
print(name_maker(“Michael”, “Jaskson”))
~~~
Output:
Michael Joseph Jaskson
Function annotations
Function annotations gives an indication of the expected return data type.
def word_multiplier(word: str, times: int) -> str:
return word * times
print(word_multiplier(10,16))What are the steps the steps to create a Function annotation?
def word_multiplier(word : str, times : in*) -> str:
return word * timesExplination:
def funcation_name(variable: < data type>str, variable: < data type>int) -> < data type>str