Python style advice
Batista, Facundo
FBatista at uniFON.com.ar
Tue Feb 10 08:21:54 EST 2004
Nick Craig-Wood wrote:
#- This is very similar to the python statement
#-
#- a, b, c = array
#-
#- BUT, the Python will throw an exception if array isn't exactly 3
#- elements long, wheras the Perl will work for any length of @array,
#- either throwing away excess elements or setting the variables to
What is an array?
If you mean a list, list are encouraged to be used when you're not certain
of the length of the array, when the length has no meaning by itself (for
example, the files in a directory).
In this case, that asignment has no future. You don't want a special name
for the first element of the list, and other different name for the second
one.
Otherwise, if with array you mean a tuple, tuple are encouraged to be used
when its length and element positions are meaningful (for example, the
position of a point in space, (x,y,z)).
In this case, that asignment is ok: with the example of the point, it's ok
to do "(x,y,z) = pointInSpace". But in this case, you'll *always* have three
elements. Not two or four, three.
Disclaimer: the differences about mutability don't apply here.
. Facundo
More information about the Python-list
mailing list