print and println@printftry-catch for Exception HandlingfinallyThe Julia REPL (Read-Eval-Print Loop) is your primary tool for interacting with Julia directly. It's an environment where you can type Julia code, have it executed immediately, and see the results. This makes it perfect for trying out small code snippets, learning the language, and quick calculations. Think of it as a direct conversation with the Julia interpreter.
To start the REPL, open your terminal or command prompt and type julia, then press Enter. If Julia was installed correctly and its bin directory was added to your system's PATH, you should see a banner with Julia version information, followed by the Julia prompt:
julia>
This julia> prompt is where you'll type your commands. Let's explore what you can do.
The REPL is ready to evaluate Julia expressions. Try some simple arithmetic:
julia> 2 + 3
5
julia> 10 * 4 - 5
35
Julia reads your input (2 + 3), evaluates it (calculates the sum), prints the result (5), and then loops back to show the prompt again, ready for your next command.
You can also define variables:
julia> message = "Hello, Julia learners!"
"Hello, Julia learners!"
julia> x = 100
100
julia> y = x / 4
25.0
To see the value of a variable, just type its name:
julia> message
"Hello, Julia learners!"
The REPL conveniently prints the result of the last evaluated expression. If an expression doesn't explicitly return a value (like an assignment, which technically returns the assigned value), the REPL will show it. If a function like println is used, which primarily performs an action (printing to the console) and returns nothing, the REPL won't print an additional line for nothing unless it's the only result.
julia> println("This is a test.")
This is a test.
The Julia REPL has a few special modes accessible by typing a specific character at the beginning of an empty line. These modes offer powerful built-in functionalities.
Different modes available in the Julia REPL and how to switch between them.
Help Mode (?)
If you want to know more about a function, type, or module, type ? at an empty julia> prompt and press Enter. The prompt will change to help?>. Now, type the name of what you're curious about:
julia> ?
help?> println
search: println print printstyled sprint isprint islink issticky Sprintln
println([io::IO], xs...)
Print (using print) xs followed by a newline.
If io is not supplied, prints to stdout.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> println("Hello, world")
Hello
julia> io = IOBuffer();
julia> println(io, "Hello")
julia> String(take!(io))
Hello\n
help?>
This displays the documentation (docstring) for println. To exit help mode and return to the normal julia> prompt, press Backspace at an empty help?> prompt, or simply press Enter on an empty line.
Shell Mode (;)
To run shell commands directly from the REPL (like ls on Linux/macOS or dir on Windows), type ; at an empty julia> prompt and press Enter. The prompt will change to shell>.
On Linux or macOS:
julia> ;
shell> ls
Desktop Documents Downloads Music Pictures ProjectA
shell> pwd
/Users/yourusername
shell>
On Windows:
julia> ;
shell> dir
Volume in drive C is OS
Volume Serial Number is XXXX-XXXX
Directory of C:\Users\yourusername
01/10/2023 09:00 AM <DIR> .
01/10/2023 09:00 AM <DIR> ..
...
shell>
To exit shell mode, press Backspace at an empty shell?> prompt or type exit and press Enter.
Package Mode (])
Type ] at an empty julia> prompt to enter package mode. The prompt will change to pkg>. This mode is for managing Julia packages (libraries), such as adding new ones or updating existing ones.
julia> ]
pkg> status
Status `~/.julia/environments/v1.9/Project.toml` (empty)
We will explore package management in detail in Chapter 6. For now, just know that this mode exists. To exit package mode, press Backspace at an empty pkg> prompt or press Ctrl+C.
These modes, the REPL has several features to make your interactive sessions more productive:
ans Variable: The result of the last successfully evaluated expression is always stored in a special variable called ans.
julia> 21 * 2
42
julia> ans
42
julia> ans + 8
50
Tab Completion: This is an incredibly useful feature. Start typing a variable name, function name, module name, or even a file path, and press the Tab key. The REPL will attempt to complete it for you. If there are multiple possibilities, it will show them.
julia> prin<Tab>
print print_shortest print_unescaped println printstyled
julia> pri<Tab>ntln("Tab completion is great!")
Tab completion is great!
History Navigation: You can access previously entered commands using the Up (↑) and Down (↓) arrow keys. This is helpful for re-running commands or correcting typos without retyping the entire line.
Ctrl+R and then typing a part of the command you are looking for.Clearing the Screen: To clear the terminal screen, you can usually use Ctrl+L.
Multiline Input: If you are typing a long command that spans multiple lines, such as a function definition or a loop, the REPL will automatically detect it and allow you to continue on the next line until the expression is complete. The prompt might change slightly or indent to indicate you are in a multiline block.
julia> for i in 1:3
println("Iteration: ", i)
end
Iteration: 1
Iteration: 2
Iteration: 3
When you're finished with your Julia session, you can exit the REPL in a few ways:
exit() and press Enter.Ctrl+D on an empty line.Ctrl+Z and then Enter on an empty line (though Ctrl+D might also work in some modern terminals like Windows Terminal).The REPL is an excellent environment for learning Julia. It provides immediate feedback, allows for quick testing of ideas, and helps you become familiar with Julia's syntax and functions. Don't hesitate to experiment with different commands and explore its features as you progress through this course.
Was this section helpful?
© 2026 ApX Machine LearningEngineered with