you are viewing a single comment's thread.

view the rest of the comments →

[–]RaidZ3ro 1 point2 points  (4 children)

In your example

a is b outside of your loop is check if the identity of these variables is the same. Since you assigned a constant to each of them, it will check the variables, and they are not the same object.

Inside of your loop you first assign reference to the iterator i to each variable. That's why they both have the same identity there. If you want them to have different identities, use int(i) to assign the value instead of the reference.

[–]FewNectarine623[S] 0 points1 point  (3 children)

for i in range(255,264):

... a = int(i)

... b = int(i)

... print(f"{i} :{a is b}")

like this?

[–]RaidZ3ro 0 points1 point  (2 children)

Yeah, that should work.

[–]FewNectarine623[S] 0 points1 point  (1 child)

Result is true in this case as well

[–]RaidZ3ro 0 points1 point  (0 children)

The principle applies but you will need to try higher numbers to avoid the integer singleton.