Kotlin Programming Cookbook
上QQ阅读APP看书,第一时间看更新

There's more...

We have used string templates in print statements. Note how we are able to access a variable using the $ symbol before the name of a variable:

println("$a is a number something”)

We can also put a piece of code in strings that are evaluated and whose results are concatenated into the string. In this case, $ is followed by {}, inside which we put our code:

println("some variable whose value: ${if(a < 100) 25 else 29}")