Chapter 10
Comparison operators
We should talk somewhat more about ==. It's a kind of examination administrator,
explicitly it's the fairness administrator. As you learned in the last section,
you use it to contrast two things with check whether they're equivalent.
You can utilize the equity administrator to
contrast a variable and a string, a variable with a number, a variable with a
numerical articulation, or a variable with a variable. Also, you can utilize
the uniformity administrator to look at different mixes. The entirety of coming
up next are legitimate first lines in if articulations:
on the off chance that full name
== "Mark" + " " + "Myers": if
full name == first name + " "
+ "Myers": if
full name == first name + " " + last name: if
total cost == 81.50 + 135: if
total cost ==
materials cost + 135: if the total cost
==
materials cost + labor cost: if x
+ y == a - b:
At the point when
you're contrasting strings, the fairness administrator is case-delicate.
"Rose" doesn't rise to "rose."
Another examination administrator, = is something contrary to ==. It implies isn't equivalent to.
1 if your ticket number! =
487208:
2 print ("Better karma
sometime later.")
Like ==, the not-equivalent administrator can be
utilized to think about numbers, strings, factors, math articulations, and
blends.
Like ==, string correlations utilizing the
not-equivalent administrator are case-delicate.
The facts demonstrate that "Rose”! = "rose".
Here are 4 more
examination administrators typically used to think about numbers.
> is more noteworthy than
< is not exactly
>= is more noteworthy than or equivalent to
<= is not exactly or equivalent to
In the models
underneath, all the conditions are valid.
if 1 > 0:
if 0 < 1:
if 1 >= 0:
if 1 >= 1:
if 0 <= 1:
if 1 <= 1:
No comments:
Post a Comment