String Templates

Why string templates are needed

In programs, we often create strings with embedded values of expressions. Concatenating values to create strings using the + operator makes the code verbose and hard to maintain. String templates solve that problem by providing an elegant solution.

How to use string templates

Within a double-quoted string, the $ symbol can prefix any variable to turn that into an expression. If ...