← Kotlin Programming learning path
Kotlin Programming · Module 2 of 10

Variables, types and strings

Use val, var, basic types and string templates.

📖 Key ideas

  1. val is read-only; var can change.
  2. Types: Int, Long, Double, Boolean, Char, String.
  3. Type inference: val x = 5 is Int.
  4. String templates: "Total: ${a + b}".
  5. Multi-line strings with triple quotes.
💡 Real-life example: val is writing in ink; var is writing in pencil.
valRead-only variable
varMutable variable
String template$name or ${expr} inside strings
Type inferenceCompiler deduces type