Python Forum

Full Version: Help required over a confusion
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I just want to know that why we don't use == operator with while / for loop?
Feel free to use == any where an equality check is needed.
Thanks but pycharm is showing error while using this in a code ;
x=0
while (x>==0):
    print(x)
Because that is not == you want just >= not >==.
That's the reason i m getting confuse ..
scenarios are;
1) if we use while (x==10)----it works perfectly.
20 But if we use while (x<=10)-----this shows error to not to use double is equal to sign.

Confusion is why we dont use double == sign while using with another operator whereas if we use == independently
then no error...
== is used to distinguish the operator from assignment, where = is used. We don't need to distinguish >= from =, because they are obviously different, so we don't use >==.
Maybe your thinking because < is less than and == is equal that you could combine them to make less than or equal.
They are set symbols that are used individually.
#Operation Meaning
<          #strictly less than 
<=         #less than or equal 
>          #strictly greater than 
>=         #greater than or equal 
==         #equal 
!=         #not equal 
is         #object identity 
is not     #negated object identity 
Thanks Sir, got the point.