list = var => list.append(var) (phpstyle)
erno-news at erno.iki.fi
Mon Jul 16 15:00:30 EDT 2001
[reformatted for your reading pleasure]
In article <9iqlgi$kbg9g$1 at ID-11957.news.dfncis.de>, "Emile van
Sebille" <emile at fenx.com> writes:
|| "Alex Martelli" <aleaxit at yahoo.com> wrote in message
|| "Nick Perkins" <nperkins7 at home.com> wrote in message
|| news:LF447.476898$eK2.98947068 at news4.rdc1.on.home.com...
||| I think it should be neet if it would be possible to append a variable
||| to a list by just using
||| list_var = var_to_append
||| It works that way in PHP and I think it's nice.
||| Any comments?
|| list_var += var_to_append
|| (which is how you express this today in Python) is equivalent
|| and shorter. Python does NOT go out of its way to provide
|| a zillion ways to write the same, identical thing.
| Alex is right as long as var_to_append is already a list.
>>> l1 = 
>>> l2 = 
>>> l1 += l2
| For non-lists though you can also do
| list_var += 1,
| list_var += (1,)
hmm, does the sequence protocol really include __add__ing arbitrary
sequences? one would think lists would support it too if that
was the case.
More information about the Python-list