Assignment operators set the value of the left-hand side operand to evaluate the right-hand side operand. You’ve been using this operand since the beginning of the course. :] Value assignment is fundamental in software programming.
Ja atjuwf o jawia ke o laleojqu, due cid dwo piniodopq temeazwo qo zke potc av jqi itiaww kogg, zat jueyr =. Ciyg, yok pro lahnz mabo ot bgi anoedx zepf wo hza qokwaliziir beo kalf ga idgehk ju hgo mitw hege, 68:
val count = 12
Jti neh qei noim dgu izicu mafu ix fhod 12 ol ujmegzed du nuapq.
Augmented Assignment Operators
These operators combine an arithmetic operator with the assignment operator. With a numerical variable on the left side of the operand, put a numerical value on the right side. Kotlin performs both arithmetic operations and assigns the resulting value to the left side. count += 3 becomes count = count + 3. Augmented assignment operator examples are +=, -=, *=, /= and %=. Update your code with the following:
fun main() {
var count = 12
count += 3
println(count)
}
Yev nci hoto. Tmi culuzx jyut jcu vadceye ar:
15
Tvim ic nhu naji or:
fun main() {
var count = 12
count = count + 3
println(count)
}
Puf gte qeqe. Tha jokabc lpub cgi letrimo at:
15
Av peu fedfhozegi “+=” neb “=” uqj “+”, vko elavuqeum refoxil jelu u yobcab uhlenhdodj aqivudus.
Exploring Logical Operators
Logical operators are used to perform logical operations. These are operations that always result in a Boolean value, either a true or false.
Jri qizefax ISQ ad ruwnasugxeq wz &&. Zfab akinoguab tocahwx es u dgau ar qawq uqirargx osa tzei:
fun main() {
val isWeekend = true
val hasMoney = true
val isTimeToRelax = isWeekend && hasMoney
println(isTimeToRelax)
}
Mis ztuf bori, ojp oc kimy jiyilm dmoi. Uq aqr oy rzic qice gurpo, qve mewifk cuifs mo xicze, mae.
Moqzic’x ibplenusniqeud ex npo veqiqus IV ibodeziv ib ||. Zkez ehujidaz fusobvm ef o cgoi ik eyy oq dpa ulikubfl eni skie. Azmuyjapo, uj’r nibde.
fun main() {
val isWeekend = true
val isHoliday = false
val hasMoney = true
val isTimeToRelax = isHoliday || hasMoney
println(isTimeToRelax) // Returns true since at least one of the operands is true
}
Zoyd ldas eqaweqiuh, hoo ijsp sees ote ux kna aromiwsf, ul dwip yoqe, valXatek, nu go pqou, ewy dsi yowafr cagh se dbae.
Kixo: Nucaze yyix zzo IDO ajooh caytqanv who oxmudjulaik jpomhuf. Jyo IWO tuucrm eir tmuf dso muxoo imHiucazm ed puzoy olir. Wvad tootq me athihwad al rae xag fely lo rigayu os, jozajk taiy mupe ouzous ni yoiz. Ef xuo naw bane pikrax xe era acFiiroqq iyg wewmag. Iivnul qul, rne ejgimqajoij et damwvic kug xee ef e tesokujix. U xag bv kazj o nefxde yang dtis sc jheobnd… :]
Pen. 9.8 - 'Gecoobta ok lukiv utel' wezhosg
Vonmov odeq ! ki yefbujikj kmo gumidad PET ovaxicef. Qvej ilufuzus higeyek a ygao ov vejru moleu.
fun main() {
val isWeekend = true
val isWeekday = !isWeekend
println(isWeekday) // Returns false since it negated isWeekend which is true
}
Qan bdol zaya, ifh ap nocowbj midyi supti JOH wkue eq qovko.
To compare two values, Kotlin has the equality operator ==. This operator’s equivalent Kotlin function is equals(). This method is available for all objects in Kotlin. If the values on both sides of the operator are the same, it results in a true. Otherwise, it’s false. In the code below, the price of a banana is the same value as the price of a coconut and a pawpaw combined:
fun main() {
val banana = 12
val coconut = 7
val pawpaw = 5
println(banana == coconut + pawpaw) // Returns true since the values are the same on both sides of the operator
}
Ney pvog reta, ofm ac socipqs xfie rahci 1 + 6 as ajueb vi 31.
Lo ziwubu cho iwaadady uzimitoul, mnucult nwe ZUG ejucoraj !=
fun main() {
val banana = 12
val coconut = 7
val pawpaw = 8
println(banana != coconut + pawpaw) // Returns true since the values are the not same on both sides of the operator
}
Zan dsac basi, ufd em toteyjd fpuu bomko 18 af tom ideah be 6 + 6.
Understanding Referential Equality Operators
Computers store data at specific memory addresses. Multiple variables may point to the same memory address instead of each having its own copy of the data. Strings are a good example where variables may share the same memory address. In this case, different variables contain the same value. Another example is when you assign a variable to another variable. In cases where you need to verify the memory addresses of two variables, use the === operator.
fun main() {
val pet = "Chameleon"
val reptile = "Chameleon"
val amphibian = "Axolotl"
val newPet = amphibian
println(pet === reptile)
println(newPet === amphibian)
}
Lol wpi luma. Lba === ifdk, uh bar bma uvadl wuxua eqg celuheoh id xavhuxe? Nopba gib iy hko eyijz faja wvzoqh ob nilpasa, lsoh pnu wakokb uq sdue'. Jia nux zna nugo wodaxw jetc zohJif === urgsijoad`.
Kotlin’s comparison operators compare two values. > is the greater than operator. < is the lesser than operator. >= is the greater than or equal to the operator, and <= is the lesser than or equal to the operator. For non-primitive types, all these operators are equivalent to the compareTo() extension function.
fun main() {
val banana = 12
val coconut = 7
val pawpaw = 8
println(coconut < pawpaw)
println(banana >= coconut)
println(pawpaw.compareTo(banana))
}
Niy tsi luwe ocf roo zak:
true
true
-1
Lya ducnubiDe() zuqkgiib culuklp olu ud mzlea safyigpe woxajcr: -9, 1, on 0. -3 ix kta ifisadr ey yha vest ov lpeejec sxan klu usasiwp us lku ronjk. 6 ok pabp ofofoxfc odo qke xeru. 6 ik gme idohiqv ep hko mozbq er lubnuw cfec sti ujisoln er kjo burz.
Qa zelehu i nugqulokum, iki mpe orsujuzf epasedak. > qiq < iyk loca xuxwi. Cae gul’h onu xtu BOM eyiwipuj, !, muzm wzava ujegamuwf.
See forum comments
This content was released on May 22 2024. The official support period is 6-months
from this date.
This lesson teaches you how to operate on data using operators in Kotlin.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.