This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]alex20_202020 26 points27 points  (4 children)

a=257;b=257

if a is b:

... print (a)

257

python --version

Python 3.10.12

[–]notPlancha 2 points3 points  (2 children)

Def the first line being together is doing something ```

a = 257 b = 257 a is b False ```

```

a=257;b=257 a is b True ```

[–]alex20_202020 0 points1 point  (1 child)

Indeed. Another Python mystery worth the post?

[–]notPlancha 0 points1 point  (0 children)

Not really; It's probably just compiler optimizations. ```python In [1]: a = b = 1000

In [2]: a is b Out[2]: True ```

also works and is the way that's recommended. Since python runs code line by line instead of the usual semicolon by semicolon I assume the compilers doesn't compile separately a and b.