0

Why is this false ?

Print( “p” is “p” , [] is [] ) True false

16th Oct 2020, 6:37 PM
Curious Ant
Curious Ant - avatar
1 ответ
+ 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 ★