Python Forum
Help required over a confusion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help required over a confusion
#1
Hi, I just want to know that why we don't use == operator with while / for loop?

Reply
#2
Feel free to use == any where an equality check is needed.
Reply
#3
Thanks but pycharm is showing error while using this in a code ;
x=0
while (x>==0):
    print(x)
Reply
#4
Because that is not == you want just >= not >==.
Reply
#5
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...
Reply
#6
== 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 >==.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#7
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 
Reply
#8
Thanks Sir, got the point.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020