Complete Kotlin Tutorial: Part 5 (Basics of Functions)

Ajit Kumar Sahoo
6 min readMay 21, 2022

If you are new to this series, start from here

The previous post, Part 4 is here

Now, let’s continue with our journey by playing with functions.

The general idea regarding a function is that it accepts an input and gives an output. So, a function is made for a specific purpose. In order to invoke the function, we have to call it by its name.

I have talked about library functions and user-defined functions earlier, but not in detail.

Kotlin Standard Library Functions

main(), println(), print(), sqrt() are some examples of library functions in Kotlin. These functions are built-in functions provided by the Kotlin.

Look out:-

kotlin-stdlib — Kotlin Programming Language (kotlinlang.org)

Here’s the code-

import kotlin.math.sqrt

fun main(){
val n = 9.0
val p = 7

println(sqrt(n).toInt())
print(p)
}

Here, I have used four library functions viz., main(), println(), print() and sqrt() function. sqrt()

--

--