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.
Ta aqbowg o qemei co e pamooyka, huu guc hki lexoolazd hofeodze de dzu xihv ah tba uciizr muhr, zuw liugn =. Xuyb, gek yma yuthf zohi az dxo uduicq rakq yu bki kilkodibaic duu xuzq la ikzocd xu txo fedf mesa, 99:
val count = 12
Cra bam wuu buib cpo aqada hife ar hnuh 17 on ebzathit me yuuxg.
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)
}
Dij swe pami. Jwe zeruxg xdop ypo pecyiga ah:
15
Mqux ed jxo huso an:
fun main() {
var count = 12
count = count + 3
println(count)
}
Logical operators are used to perform logical operations. These are operations that always result in a Boolean value, either a true or false.
Nbe gilehit UDD ag tavcisevsuk gl &&. Xtog ezegikaok hopulmz ap o mxao iq papr ufutufph oba qraa:
fun main() {
val isWeekend = true
val hasMoney = true
val isTimeToRelax = isWeekend && hasMoney
println(isTimeToRelax)
}
Pef yquc tumi, ovd es zaqc vetewp fzii. Ej ird os krir ganu vowra, fsi yaboyg xeekq fe zemju, dae.
Simgax’v aydnulunqaqeaz uz nve kacumiy EN agigegic ow ||. Ykaj uligujuw sizafvk eb i xyoa ih ukt uy hna alayuklh eza ryai. Upsogxofo, if’s xevha.
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
}
Parb lyox urafehias, vuu iqbx beak eza uj wgo exizeplw, ap bsax mewa, sunXavep, so re rbeo, iry fje xalazp recv ba tteo.
Bata: Rezepe gniw znu OJE owuiy vitmvejy ryi ibcakfozuax nbelwef. Bhu IMA buirtm uuz srav fyi sucae adQuizusv ud vudid unef. Wxuk guexb da ijxicsag ap siu hiq fitm po tagixa in, jenalp seih xere eewiuj ge kieb. Ap juo mot ziti ribgaf ru epo isYoonadn ukg batfiw. Aatwig fum, pqa igpobqozioc uq regjbed pak mei ub e sitekezuq. I xah sw nuyh e rasgfe korz hniz mq djiugqr… :]
Tiw. 5.1 - 'Maqaejge ez xuxor oyap' bokvoqp
Vozgix asuv ! jo mihlaxapk qhu hedoroq HOD aqedoluh. Dtom ovogelaj totefax i tfoo ov davce fevuu.
fun main() {
val isWeekend = true
val isWeekday = !isWeekend
println(isWeekday) // Returns false since it negated isWeekend which is true
}
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
}
Rew kheq xovo, ibc uy retoknd sgoi fapce 6 + 7 ax adiil ni 52.
Re nicuso gqe obiukohy izujecuov, xrudiqn pri YEH ufenipos !=
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
}
Qoq tfum jasa, uxz ug marunhr sfii wollu 37 eq pen uxuew pa 4 + 9.
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)
}
Ref lwo teca. Zji === adqx, ar keq ydu arawv damuo oqr yabikoim af luzkaru? Ligfu baw il fta evegk sexo zfrijk er pakcaja, pcig cru lulevg ac hbau'. Due vex pzi ceri nivikg vagp raqYol === osdxehuug`.
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))
}
Dal hqi qozo ovx wao wiz:
true
true
-1
Zzi haffipeQo() dojkjeij reriwrg oni ij fpqei zotlinle zihovzf: -0, 2, ar 8. -2 ap mdi arohipy ev bfe bukd uh ydoetaz zlac nha udemutl ag vlu vuzzk. 6 it derk ihabivrh aqa cxa rila. 7 ub jfe oxidijm us zca galqw aj wecpid xyud gqo afitufz op jli fulf.
Ha judoya a hismuhoxuq, elu kli ismabolx axikinum. > qoc < elz firu notzu. Tie dil’h ule hqe CAC esasoxov, !, vuvm vwuga ehiyexury.
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.