[Tutor] basic Qs [tutorial / text editors / performance characteristics]

Gonçalo Rodrigues op73418@mail.telepac.pt
Fri Feb 14 07:28:01 2003


----- Original Message -----
From: "siddharth" <siddharth178@hotmail.com>
To: <tutor@python.org>
Sent: Friday, February 14, 2003 3:53 AM
Subject: Re: [Tutor] basic Qs [tutorial / text editors / performance
characteristics]


> thanks for such quick response   :)
>
> i know Java in detail and currently i am working as 'software engineer'
> i do know other langs like c c++ etc.
>
> what will be good starting point for me ?? any suggestions ?
>

Just hack away at the tutorial that comes with Python. Since you already
have experience, most likely you'll get on par with Python in no time. Do
you have any specific needs?

> i would also like to know whats the main adv. and disadv. of using lists
and
> tuples ?? ( tuples are some what confusing me )
>
>

tuples are like lists, except you can't mutate them. With a list you can do:

>>> a = [1, 2, 3]
>>> a.append(4)
>>> print a
[1, 2, 3, 4]
>>> a[0] = "Changed!"
>>> print a
['Changed!', 2, 3, 4]

With a tuple, once it is created you can't mutate, e.g. if you try to do the
same

>>> b = (1, 2, [])
>>> b.append(4)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: 'tuple' object has no attribute 'append'
>>> b[0] = "Changed!"
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
TypeError: object doesn't support item assignment

And to give you some food for thought here goes:

>>> b[2].append("Changed!")
>>> print b
(1, 2, ['Changed!'])
>>>

Of course, we have not mutated the tuple *itself*. We have mutated the last
object it referenced, the tuple stayed the same, e.g. has the same number of
elements, the elements it has are the same (in the sense of identity, not
equality), etc.

Hope it helps,
G. Rodrigues