Why is () is () true, yet (0,) is (0,) is false?
I thought they would be the same object. However, I’m apparently missing something.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
istests to see if both sides of the statement share the same memory address. It’s basically a shorthand forid(a) == id(b)As
()happens fairly frequently, it is actually treated as a singleton by the Python Interpreter (just like integers from 0 to 255, empty strings, empty lists, etc.). When comparing(0, )to(0, )to the interpreter they are actually different variables in memory. If they were mutable, you could modify the first, and the second wouldn’t change, hence they are not the same (a is not b).