On Tue, Jun 15, 2021 at 5:12 AM Jach Feng <jf...@ms4.hinet.net> wrote:
>
> >>> n = [(1,2) for i in range(3)]
> >>> n
> [(1, 2), (1, 2), (1, 2)]
> >>> id(n[0]) == id(n[1])  == id(n[2])
> True

This is three tuples. Tuples are immutable and you get three
references to the same thing.

> >>> m = [[1,2] for i in range(3)]
> >>> m
> [[1, 2], [1, 2], [1, 2]]
> >>> id(m[0]) == id(m[1])  == id(m[2])
> False
> >>>
>

These are lists. Each one is distinct. You could change one of them
and the other two would remain as they are.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to