+ 1
Why cant i run this code in playground?
a = 2 b = 2 if a=b: print ("True ")
4 Answers
+ 4
because you are using only one equal sign (" = ") when you wrote the if statement "a=b" when you should be using two ("a ==b") to compare the values. "a = b" is identifying "a" as "b" (with the single "=" ) not comparing the two values as you originally intended. the correct code would have "if a == b" not "a = b" "if a == b" : it would compare the values between the two variables, and if the value of "a" is equal to the value of "b" it will prove "True" , satisfying the "if" statement and run any code indented beneath it. "if a=b" is saying if "a=b" , and "a=b" is just identifying "a" as "b" , not using any Boolean logic to compare values and return with a "True" or "False" (which is needed to satisfy the "if" statement and execute any code underneath it.) Hope I helped and explained that clearly enough. Anyone please feel free to correct or re-explain anything Ive just said as I've only started learning the first of anything on this app a few days ago.
+ 4
Don't confuse assignment ("=") with comparison ("==").
+ 3
you should use the '==' sign.Dont get confused with a comparison & an assignment
+ 2
it's about comparison .so you should use '==' sign.