from copy import deepcopy
class Foo: pass
foo = Foo()
foo.bar = 10
shallow_copies = [foo for _ in range(10)] # todos partilham as mesmas referencias, o mesmo foo e partilhado
deep_copies = [deepcopy(foo) for _ in range(10)] # copias independentes, referencias diferentes
shallow_copies[0].bar = 100 # mudar valor da propriedade de foo
deep_copies[0].bar = 100 # mudar valor da propriedade de foo
print([f.bar for f in shallow_copies]) # [100, 100, 100, 100, 100, 100, 100, 100, 100, 100]
print([f.bar for f in deep_copies]) # [100, 10, 10, 10, 10, 10, 10, 10, 10, 10]
print(all((f.bar is shallow_copies[0].bar) for f in shallow_copies[1:])) # True , todos os foo tem bar com a mesma ref
print(all((f.bar is deep_copies[0].bar) for f in deep_copies[1:]))
ZnJvbSBjb3B5IGltcG9ydCBkZWVwY29weQoKY2xhc3MgRm9vOiBwYXNzCgpmb28gPSBGb28oKQpmb28uYmFyID0gMTAKc2hhbGxvd19jb3BpZXMgPSBbZm9vIGZvciBfIGluIHJhbmdlKDEwKV0gIyB0b2RvcyBwYXJ0aWxoYW0gYXMgbWVzbWFzIHJlZmVyZW5jaWFzLCBvIG1lc21vIGZvbyBlIHBhcnRpbGhhZG8KZGVlcF9jb3BpZXMgPSBbZGVlcGNvcHkoZm9vKSBmb3IgXyBpbiByYW5nZSgxMCldICMgY29waWFzIGluZGVwZW5kZW50ZXMsIHJlZmVyZW5jaWFzIGRpZmVyZW50ZXMKCnNoYWxsb3dfY29waWVzWzBdLmJhciA9IDEwMCAjIG11ZGFyIHZhbG9yIGRhIHByb3ByaWVkYWRlIGRlIGZvbwpkZWVwX2NvcGllc1swXS5iYXIgPSAxMDAgIyBtdWRhciB2YWxvciBkYSBwcm9wcmllZGFkZSBkZSBmb28KCnByaW50KFtmLmJhciBmb3IgZiBpbiBzaGFsbG93X2NvcGllc10pICMgWzEwMCwgMTAwLCAxMDAsIDEwMCwgMTAwLCAxMDAsIDEwMCwgMTAwLCAxMDAsIDEwMF0KcHJpbnQoW2YuYmFyIGZvciBmIGluIGRlZXB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