When we are writing a program, we may have a piece of information that will need to be referred to from other places in our program. Values and variables are used for this. They are defined using the keywords val and var, respectively. We can think of vals and vars as boxes containing items of data. A var is a box from which the data may be removed and replaced with some other data item. With a val, however, the data item is set once and can never be replaced.
6. Values and Variables
Get Learn to Program with Kotlin: From the Basics to Projects with Text and Image Processing now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.