+ 2

why printļ¼ˆ7=7.0ļ¼‰have error

printļ¼ˆ7>=7.0ļ¼‰is true

22nd Dec 2016, 11:49 AM
SealCLi
SealCLi - avatar
6 Answers
+ 5
In computer programing, the "=" ( equal sign ) is an operator for affectation, when in mathematical world it is an operator for equality. So, the equivalent operator for equality in code is "==" ( double equal sign )... and in certains langage is added the concept of "strict equality" ( "===" -- triple equal sign ), because object models and variables concept needs to be more precise in certains cases ( if I have 2 objects of a same family, ie: 2 vehicules, one car and one boat, I can tell there are equals if I consider the fact that they are two vehicules, or that there aren't, considering car and boat different )
22nd Dec 2016, 12:11 PM
visph
visph - avatar
+ 1
They are different types. If no quotations are added the program is going to assume you are using a variable or an integer. If you want a simple string printed, use the quotes. But python isn't going to be able to make two objects/variables interact if they are a different type.
22nd Dec 2016, 5:25 PM
Devin
+ 1
Read the hint given "don't confuse assignment (one equal sign) with comparison (two equal signs). See, python recognises 7 as integer and 7.0 as float. By using assignment ie one equal sign, you're telling it to assign the value of an integer with that of a float. See the logic? Try your best. You can do it :)
12th Jan 2017, 4:38 AM
Adwait
Adwait - avatar
0
try print(7 == 7.0)
22nd Dec 2016, 11:56 AM
Uran Kajtazaj
Uran Kajtazaj - avatar
0
print (7==7.0) will give true
1st Mar 2017, 2:13 PM
Vallapureddy Vineeth Reddy
Vallapureddy Vineeth Reddy - avatar
- 5
try print ("7=7.0")
12th Jan 2017, 12:47 AM
william gu