Why is this false ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is this false ?

Print( ā€œpā€ is ā€œpā€ , [] is [] ) True false

16th Oct 2020, 6:37 PM
Curious Ant
Curious Ant - avatar
1 Answer
+ 6
"is" checks if both operands are the same object. [] and [] are two lists that look the same but are two separate objects. "p" and "p". Here Python decided to store "p" somewhere and reuse that value instead of creating a new "p" string every time we use it in our code (research about string pooling and interning). That's why the two strings are the same thing. Tutorial: https://code.sololearn.com/c89ejW97QsTN/?ref=app
16th Oct 2020, 7:19 PM
Kevin ā˜