Kotlin Output

Kotlin Tutorial

 Kotlin Output – Complete Guide

In Kotlin, output means displaying text or values on the screen (console).
Kotlin mainly uses print() and println() for output.


 1. println() – Print with New Line

Prints output and moves to the next line.

Output

Hello Kotlin
Welcome
  •  Most commonly used
  •  Adds a new line automatically

2. print() – Print on Same Line

Prints output without a new line.

Output

Hello Kotlin

 3. Printing Variables


 


 4. String Templates (Very Important)

Kotlin uses $ to print variables inside strings.


 


 5. Expression inside Output

Use ${} for calculations or expressions.


 

Output

Sum is 30

6. Printing Multiple Values


 


7. Printing Boolean Output


 8. Printing with Escape Characters

Output

Hello
Kotlin
Tab Space
Quote: "Kotlin"

 9. Raw String Output (Triple Quotes)

No escape characters needed.

  •  Clean multi-line output

 10. Printing Objects


 

Output

User(name=Amit, age=25)

Common Output Mistakes

  • Using + instead of string templates

  • Forgetting ${} for expressions

  • Using print() when new line is needed


 Best Practices

  •  Use println() for readability
  •  Prefer string templates over +
  •  Use raw strings for multi-line output
  •  Keep output clean and meaningful

 Interview Questions – Kotlin Output

Q1. Difference between print() and println()?
println() adds a new line, print() does not.

Q2. How to print variable inside string?
Using $variable.

Q3. How to print expression result?
Using ${expression}.


 Summary

  • print() → same line
  • println() → new line
  • $ → variable output
  • ${} → expression output
  •  Triple quotes → multi-line output

You may also like...