Booleans and If statements | Sololearn: Learn to code for FREE!


Booleans and If statements

i had been trying this : num = 7 if num ==7: print("num" =="7") the output is : False but if i make this : num = 7 if num ==7: print("7" =="7") the output is : True and my question is why?

8/11/2017 10:32:54 AM

jesús lópez martín

3 Answers

New Answer


Because the first statement compares the string "num", not the value of the variable num.


You should remove the second and third quote because you want everything in the print function to be one string. Try print("num == 7") It reads your version as a question. Like "Hey code, tell me if the string 'num' is exactly the same as the string '7'. Then it will print false Another example: if you say print("num" + "7") it will print out "num7"


7 is an integer and "7" is an string 7 == "7" :False nums = "7" print (nums == "7") output: True