Sunday, 15 August 2021

Chapter 10 || Python Comparison operators

 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:


Chapter 1; 

Chapter 2; 

Chapter 3; 

Chapter 4; 

Chapter 5;

Chapter 8;



Chapter 9;

No comments:

Post a Comment

Adbox