НачатьНачать бесплатно

Default arguments

In the previous recap exercise, you specified two positional arguments for the function you created. These arguments had no restrictions around them, meaning we could pass any data type to these arguments. On top of this, if we had not specified one of the arguments when calling the function, we would have received an error.

Default arguments are one way to change this. A default argument allows us to specify a default value if we do not pass that argument into the function call.

Define a function below that takes a positional argument and then a keyword argument with a default value.

Это упражнение является частью курса

Intermediate Julia

Посмотреть курс

Инструкции к упражнению

  • Define my_profit and create a new, third argument called fees which is set to two by default. Call the function without passing a value for fees.

Интерактивное практическое упражнение

Попробуйте выполнить это упражнение, дополнив этот пример кода.

# Define my_profit with two positional arguments and a default argument
function my_profit(previous_price, current_price, ____)
	return current_price - previous_price - ____
end

my_profit(____, ____)
Редактировать и запускать код