+ 1
What is the meaning of <=,>=
Pls answer
3 ответов
+ 4
Usualy we use these operators as part of a condition. Statments like: if(), while(), for()
if(age >= 18)
print("You are welcome");
while(i <= 10)
print(i++);
>= will be evaluate to TRUE if "equals to" or "larger then"...
<= will be evaluate to TRUEif "equals to" or "smaller then"...
+ 1
smaller than or equal to, larger than or equal to
0
Are you already familiar with < and >?
<= and >= are very similar, but they have a difference.
There is a good reason why <= and >= exist.
When you want to check whether value A is greater than value B, there are 3 cases:
A is greater than B
A is less than B
A is equal to B
Give extra attention to the last given case:
A is equal to B
If you want to compare A and B with "greater than" or "less than" operators, how would you want to handle the case where they are equal, would the comparison return true or false?
That is the difference between <, > and <=, >=. In cases where compared value are equal:
< and > result to false
<= and >= result to true
When A and B are equal:
A < B ➡ False
A > B ➡ False
A <= B ➡ True
A >= B ➡ True