learning python ...
Cameron Simpson
cs at cskk.id.au
Tue May 25 00:22:06 EDT 2021
On 25May2021 05:53, hw <hw at adminart.net> wrote:
>That seems like an important distinction. I've always been thinking of
>variables that get something assigned to them, not as something that is
>being assigned to something.
They are what you thought. But it's references to objects what are being
passed around. C is a deliberately "close to the machine" language, and
things a CPU can store in a register are natural types (ints of various
sizes, etc). But consider a C string:
char *s = "foo";
The compiler here allocates some char storage, puts "foo\0" in it, and
puts a reference in "s".
char *t = strcpy(s)
char *t2;
t2 = s;
t2 = t;
Here "s", "t" and "t2" are all of type (char*), and store references.
When you pass "s" or "t" around, eg as above in an assignment, or when
you pass it to a function, you're not copying the storage, just the
reference.
Same with Python, except that all the basic types like int and float are
also done with references.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list