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 interpolation convenience feature in Julia. Interpolation can be very handy as it allows for writing output statements in an easy and clean manner. Although it is not directly related to numerical analysis interpolation, the term intersects in meaning. For functionalities related to numerical analysis interpolation, refer to the usage of Interpolations.jl.

Code

The usage is quite straightforward. Simply write the variable inside the string with a dollar sign $를 붙이면 변수가 알아서 문자열처럼 읽힌다. 변수 그대로가 아닌 계산이 필요하면 굳이 밖에서 계산할 필요 없이 $() in front of it.

julia> x = 12
12

julia> y = -2
-2

julia> println("value of x, y: ▷eq2◁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