Skip to main content

Kotlin println(): Printing values to console

How to print values in Kotlin?

Hi guys. We saw how to to declare variables in previous post and now we want to print the values to console.
  • To print values, we use the print or println function.
  • println is similar to print function. It just adds a newline after printing whatever we pass to the function
  • print functions support string interpolation which is like embedding variables in other strings. We will talk about string interpolation in our section on Strings.
  • print functions print to the standard output by default which is usually the terminate or console.
Here's how to print the values to console:
print("hello world") // prints "hello world"

println("hello world") // prints "hello world" with a new line

val PI = 3.14

println(PI) // prints "3.14"

println("The value of PI = " + PI) // concatenate the variable and print it

println("The value of PI = $PI") // embed variable in string and print it

Comments