Learn Kotlin: Basic Operators

Some of the many basic operators in Kotlin

Mathematical operations like addition, substraction, multiplication, and division comes built-in with Kotlin.

However there are more available basic operators we can use to perform operations on variables and values. Learning these operators is important as you will do operations on variable and values a lot.

In the example below, we use the + operator to add together two values, a variable with a value, and a variable with another variable.

Addition operator example

We will learn four different categories of operators : arithmetic, assignment, comparison, and logical. You can use all four of them for operations of two values, a variable with a value, and a variable with another variable just like the addition operator example above.

1. Arithmetic operators

— are used to perform common mathematical operations.

Kotlin arithmetic operators
Arithmetic operators in action

2. Assignment operators

— are used to assign values to variables.

We use the assignment operator (=) to assign a value to a variable.

For example : val x = 10

We assign the value 10 to a variable named x.

Here is a list of all assignment operators:

Kotlin assignment operators list

3. Comparison operators

— are used to compare two values and will return boolean (true or false).

Kotlin comparison operators

4. Logical operators

— are used to determine the logic between variables or values and will return boolean (true or false).

Kotlin logical operators

That’s basically it. That’s all you need to know about Kotlin basic operators. You can save this article for your future reference. Thank you so much for reading. If you like these articles, let me know in the comment section below. You can also give suggestion, I’m open for any kind of feedback.

— Learn Kotlin Series —

  1. Learn Kotlin: Introduction
  2. Learn Kotlin: Hello World!
  3. Learn Kotlin: Variables
  4. Learn Kotlin: Data Types
  5. Learn Kotlin: Basic Operators (this article)
  6. Learn Kotlin: Functions

--

--

--

Android Developer. Currently residing in Jambi, Indonesia. https://romnan.my.id

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What we owe to the community as Software Engineers

Decorating Go Error

AWS Code Deploy Setup (EC2, IAM, Github)

No Hindi On Babbel? Download 2 Free Apps

HTML TUTORIAL FOR BEGINNERS PART 7

A Tale of 3 Microcaps: HedgeTech, SuperBid, and VAIOT

Git And Github For Beginners.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Deddy Romnan Rumapea

Deddy Romnan Rumapea

Android Developer. Currently residing in Jambi, Indonesia. https://romnan.my.id

More from Medium

Java Concepts — All 50 Keywords Examples

Day47 of #100DaysOfCode

Basics of C++ Pointers and Examples with Strings

Getting Started Kotlin Language