Last answered:

07 Oct 2020

Posted on:

06 Oct 2020


Syntax warning

Hi team, I'm just wondering why it prompted out the syntax warning where I inputted the syntax as per taught?
1 answers ( 0 marked as helpful)
Posted on:

07 Oct 2020

Hi Ethan! Thanks for reaching out. The reason for this error touches upon the difference between object equality and identity in Python. This is a large and separate topic but basically, literals in Python include strings, integers, gloats, lists, tuples etc. is and is not are not supposed to be used with literals - they are to compare whether different objects contain the same values. That's why, you can execute the following result to obtain True.
a = 50
b = 50
a is b
Or this one to obtain True again.
c = 10
d = 12
c is not d
Should you compare literals directly, you can use arithmetic operators (such as == for equality and != for inequality). Hope this helps.

Submit an answer