Julia Comments
A comment is a note inside code that Julia ignores when the program runs. Comments help people who read the code later.
A single-line comment is ignored
The first line is a note for the reader. Only the second line runs.
# This line is a note
println("Hello")A block comment spans several lines
The note between #= and =# covers two lines. Julia skips the whole note.
#=
This note spans
two lines.
=#
println("After the note")A comment can follow a statement
The statement runs first on this line. The note after the # sign is ignored.
println("Visible") # This note is ignoredExample
# A program with two kinds of notes
println("First line")
#=
A longer note
about the next line.
=#
println("Second line")Key points
- Comment: a note inside code that Julia ignores.
- Single-line comment: a comment that starts with # and runs to the end of the line.
- Block comment: a comment that starts with #= and ends with =#.
- Use a block comment for a note that spans several lines.
- Placement: a comment can sit on its own line or after a statement on the same line.
In this example, the first line is a single-line comment, so Julia skips it. The first println prints First line. A block comment then spans three lines and is skipped, and the last println prints Second line.
Note
comments change nothing about what a program prints.
Try it Yourself
Edit the code, then press Run.
Running is simulated · JuliaHub
Exercise
Which symbol starts a single-line comment in Julia?