+ 1
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?
3 odpowiedzi
+ 1
Because the first statement compares the string "num", not the value of the variable num.
+ 1
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"
0
7 is an integer and "7" is an string
7 == "7"
:False
nums = "7"
print (nums == "7")
output: True