Learn Kotlin: Basic Operators
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.
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.
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:
3. Comparison operators
— are used to compare two values and will return boolean (true or false).
4. Logical operators
— are used to determine the logic between variables or values and will return boolean (true or false).
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.