DEV Community

LogicWiz Admin
LogicWiz Admin

Posted on

An AI explained Python's is and == in four lines. One of them is wrong.

We asked Aria, our AI, how is and == differ in Python. She answered in four lines and sounded completely sure:

1. == checks whether two values are equal.
2. is checks whether two names point to the same object.
3. [] == [] is True.
4. [] is [] is also True, because both lists are empty.
Enter fullscreen mode Exit fullscreen mode

One line is wrong. Think before you scroll.

.

.

.

.

.

It's line 4. Each [] builds a new list, so you get two separate objects and [] is [] is False. Being empty doesn't make them the same object. That's also why you write x is None but compare lists with ==.

We turned this kind of thing into a free game. Aria answers a coding question in 5 or 6 lines and you tap the one that's wrong, then pick why. Five rounds take about five minutes on a phone.

Our October event closes Monday 19 Oct at 11:59 pm IST, and the top 10 get LogicWiz goodies delivered home.

Play it here: https://arena.logicwiz.ai/club/BJSRBK?utm_source=devto

Did line 4 fool you?

Top comments (0)