why does 3=="3" return false although they are of the same value? doesn't the == operator checks only for the type not the value | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why does 3=="3" return false although they are of the same value? doesn't the == operator checks only for the type not the value

== operator

13th Jul 2017, 12:46 PM
mariam maher
mariam maher - avatar
7 Answers
+ 5
== does check. Datatype affects value.
13th Jul 2017, 1:49 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 6
3 is of datatype int. "3" is of datatype str. Thus they aren't the same.
13th Jul 2017, 12:49 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
yeah the value is quite different 3 is a number and "3" is a string.. and both can't be equal.. unless u convert either of them to same type
13th Jul 2017, 2:37 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 2
but what i got from the tutorial that the == operator doesn't check for the datatype isn't that right ?
13th Jul 2017, 12:53 PM
mariam maher
mariam maher - avatar
+ 2
I got it . thank you 😀
13th Jul 2017, 2:51 PM
mariam maher
mariam maher - avatar
+ 1
Bc the 3 is a string
20th Jul 2017, 11:20 PM
cadw
0
If you write only 3 , it is considered as integer and if you write with "3" then it is considered as string. And == operator checks datatype of value.
14th Jul 2017, 12:43 PM
Jignesh Gothi
Jignesh Gothi - avatar