0

Why we need double equal sign for numbers when one can do the job?

when we write: if 4+2=4:, this make sense. unless it is a string why would we use: if 4+2==4: just puzzled.

12th May 2018, 5:19 PM
Khalid Iqbal
2 Answers
+ 6
In the first one you can think of it like you're sure of the answer "2 plus 2 equals 4" there's no questioning in it. But in the latter you're asking "Does 2 plus 2 equals 4?" and the answer will be either TRUE or FALSE. and in Programming "=" is an assignment operator while "==" is a comparison operator. Like Jan Markus said.
12th May 2018, 5:23 PM
Jihad Naji
Jihad Naji - avatar
+ 1
If you use just = in an if-statement, the answer will always be TRUE. To actually make a comparison you need to use ==.
18th May 2018, 12:48 PM
Michaela M
Michaela M - avatar