Print Something More! – Kotlin’s Print Function

In the last post, we learnt that Print or Println functions help us output whatever is written inside round brackets following the function keyword. So whatever user gives in parenthesis is intended to be produced on screen with desired processing applied.

However, these two functions can output more than text strings or simply strings.

We can print numbers:

This code will output 25.

Note: The number is not in quotation marks

We can print decimal numbers:

We can churn really long numbers:

But there is a limit to what it can take as number:

We can print Boolean expressions as well:

Note: Look closely! There are no quotation marks. This is not same as writing “true” as that will be a text string.

We can perform mathematical operations:

We can do logical tests:

And another one where we checked if two texts are same or not:

In short, we can give instructions to process even inside parenthesis of Print function and it is capable of doing much more then simply throwing texts on our screens. But it will be a mess if we write Pandora of instructions right there. So we need to learn a way by which we can have a processing instruction set and the output instruction set separate. Its must easier to write and read code this way among many other benefits.

This is where variables enter the scene. We will learn about them next!

Leave a Reply

Notify of