Ad space (banner)
๐ŸŸฃJulia Lessons
Lesson 26 / 68

Default arguments

This lesson covers default argument values in Julia, with the aim of writing flexible functions whose arguments can be left out.

Writing = value on a parameter sets the initial value used when the caller leaves that argument out. Picture an order form where leaving a box blank gets you the usual set.

The sample code defines function greet(name="Guest"), which handles both greet("Alice") with a name and greet() with nothing at all.

A common early stumble is the difference from keyword arguments. Julia also has keyword arguments, separated with a semicolon ;, and each suits a different purpose.

In professional work, letting the caller omit arguments produces flexible functions that serve both simple use and fine-grained control.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Julia directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)