Re: teaching python variables

2005-12-03 חוט guy keren

On Fri, 2 Dec 2005, Amit Aronovitch wrote:

 Meta
 
 In this essay I'll try to clearly state some of my ideas about variables in
 python and how to teach the subject to students new to programming.

lets cut the long talks. in order for me to understand what you're trying
to do, i would like you to explain the following scenarios using the
terms you're suggesting:

Scenario 1:
list1 = [2, 3]
list1[0] = 1
print list1
   [1, 3]

Scenario 2:
a = 1; b = 2; c = 3
list1 = [a, b, c]
list2 = [b, c]
print list1
   [1, 2, 3]
print list2
   [2, 3]

Scenario 3:
list1 = [1, 2]
list2 = [3, 4]
mlist_a = [list1, list2]
print mlist_a
   [[1, 2], [3, 4]]
mlist_a[1] = list1
print mlist_a
   [[1, 2], [1, 2]]


-- 
guy

For world domination - press 1,
 or dial 0, and please hold, for the creator. -- nob o. dy


RE: teaching python variables

2005-12-03 חוט RaeNye
Can I try?

Please verify that I use the same explanation for each syntactic form (list
constructor, __setitem__, assignment operator).
Also, please see that I refrain from mentioning variables and references.

Hope that'd pour some light,
R.

Scenario 1:

list1 = [2, 3]
Let there be a list built up from two elements: the number 2 and the number
3. We call it list1.

list1[0] = 1
We change the thing called list1 (which happens to be the object we
created one sentence ago) by replacing its first element from whatever it
was to the number 1.

print list1
   [1, 3]
Now examine the thing called list1 - it contains two elements: the first
is the number 1 (since we changed it to be so) and the second is the number
3 (since it didn't change from the time the object was born).

Scenario 2:

a = 1; b = 2; c = 3
We name the number 1 a, the number 2 b and the number 3 c.

list1 = [a, b, c]
We create a list built up from three elements: the object named a (i.e.,
the number 1), the object named b (i.e., the number 2) and the object
named c (i.e., the number 3). We call it list1.

list2 = [b, c]
We create a list built up from two elements: the object named b (i.e., the
number 2) and the object named c (i.e., the number 3). We call it list2.

print list1
   [1, 2, 3]
The object named list1 consists of the number 1, the number 2 and the
number 3. That exactly how it was bulit.

print list2
   [2, 3]
The object named list2 consists of the number 2 and the number 3. That
exactly how it was bulit.

Scenario 3:

list1 = [1, 2]
list2 = [3, 4]
We create two lists, named list1 and list2 respectively (with the
obvious content: the number 1 ...)

mlist_a = [list1, list2]
We create a list built of the object named list1 and the object named
list2 (which are the same two lists created above). We call it mlist_a.

print mlist_a
   [[1, 2], [3, 4]]
Obvious.

mlist_a[1] = list1
We change the thing called mlist_a (which happens to be the object we
created two sentences ago) by replacing its first element to the object
named list1.
Note that now the object named mlist_a contains the same object as both
the first and the seconds element: a list that consists of the number 1 and
the number 2.

print mlist_a
   [[1, 2], [1, 2]]
Obvious, considering the last note.


-Original Message-
From: guy keren [mailto:[EMAIL PROTECTED] 
Sent: Sunday, December 04, 2005 1:44 AM
To: Amit Aronovitch
Cc: python@linux.org.il
Subject: Re: teaching python variables


On Fri, 2 Dec 2005, Amit Aronovitch wrote:

 Meta
 
 In this essay I'll try to clearly state some of my ideas about 
 variables in python and how to teach the subject to students new to
programming.

lets cut the long talks. in order for me to understand what you're trying to
do, i would like you to explain the following scenarios using the terms
you're suggesting:

Scenario 1:
list1 = [2, 3]
list1[0] = 1
print list1
   [1, 3]

Scenario 2:
a = 1; b = 2; c = 3
list1 = [a, b, c]
list2 = [b, c]
print list1
   [1, 2, 3]
print list2
   [2, 3]

Scenario 3:
list1 = [1, 2]
list2 = [3, 4]
mlist_a = [list1, list2]
print mlist_a
   [[1, 2], [3, 4]]
mlist_a[1] = list1
print mlist_a
   [[1, 2], [1, 2]]


--
guy

For world domination - press 1,
 or dial 0, and please hold, for the creator. -- nob o. dy