constructors for lists and tuples
Dr. Des Small
des.small at bristol.ac.uk
Tue Dec 11 09:14:03 EST 2001
nbecker at fred.net (N Becker) writes:
> what are the constructors for lists and tuples?
[] and () respectively.
> I wanted to make a
> list of a known size and then populate it. Based on my experience
> with C++ and STL, I expected to find a constructor that took a
> size.
Python isn't C++, thankfully. What you want is
<transcript>
>>> foo=10*[None]
>>> foo
[None, None, None, None, None, None, None, None, None, None]
>>> foo[0] = 'a'
>>> foo
['a', None, None, None, None, None, None, None, None, None]
</transcript>
Des.
--
Dr Des Small, Scientific Programmer,
School of Mathematics, University of Bristol,
Tel: 0117 9287984
More information about the Python-list
mailing list