logo

How to Conveniently Print Variable Values in Julia, Interpolation 📂Julia

How to Conveniently Print Variable Values in Julia, Interpolation

Overview

This section explains the convenient feature of interpolation in Julia. By using interpolation effectively, you can make output statements simple and clean, which is very handy. Although it is not related to interpolation in numerical analysis, the meaning of the word is similar. For features related to numerical analysis interpolation, refer to the usage of Interpolations.jl.

Code

The usage is very simple. You can append the dollar sign $ before a variable inside a string to automatically read the variable as a string. If a calculation is needed, you can include the expression inside $() without needing to calculate it separately.

julia> x = 12
12

julia> y = -2
-2

julia> println("value of x, y: $x, $y")
value of x, y: 12, -2

julia> println("value of x+y: $(x+y)")
value of x+y: 10

Environment

  • OS: Windows
  • Julia: v1.5.0