Ben Finney <b...@benfinney.id.au>: > Many established and still-popular languages have the following > behaviour:: > > # pseudocode > > foo = [1, 2, 3] > bar = foo # bar gets the value [1, 2, 3] > assert foo == bar # succeeds > foo[1] = "spam" # foo is now == [1, "spam", 3] > assert foo == bar # FAILS, ‘bar’ == [1, 2, 3] > > This is because such languages treat each variable as “containing” a > value.
I don't think that has much to do with variables but rather the values. What you are describing is that Python has pointer semantics. Your example, properly understood and translated, will yield Python-esque results in any programming language: #!/bin/bash a = /tmp/xyz touch $a b = $a cmp $a $b || exit echo z >>/tmp/xyz cmp $a $b || exit #include <stdlib.h> #include <assert.h> int main(void) { int *a = malloc(sizeof *a); *a = 7; int *b = a; assert(*a == *b); *a = 8; assert(*a == *b); return 0; } Marko -- https://mail.python.org/mailman/listinfo/python-list