From d98f46ce647846b0aa30b2e16a30fd4e152a1bf5 Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Thu, 10 Jul 2025 22:55:07 +0200 Subject: Add new code Signed-off-by: Carlos Maiolino --- mit/mutation.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mit/mutation.py (limited to 'mit/mutation.py') diff --git a/mit/mutation.py b/mit/mutation.py new file mode 100644 index 0000000..41449fd --- /dev/null +++ b/mit/mutation.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 + +# Mutation / Aliasing / Cloning + +colors = ['blue', 'pink', 'green'] +colors2 = ['blue', 'pink', 'green'] +new_colors = colors ### This is a new pointer to colors + ### Does it work with tuples too? + +clone = colors[:] ### This clones the list instead of creating a new pointer + ### to the same place +colors.append('red') + +print(new_colors) +print(new_colors == colors) +print(colors == colors2) # Two different structures, same content + # Will print false, bcause they point to different + # memory locations + +print(clone == colors) -- cgit v1.2.3