In "Learning Python," by Lutz and Ascher, there's a table showing different
assignment statement forms. One form shown is list assignment. The authors
give this as an example:
[spam, ham] = ['yum', 'YUM']
I don't see how this is any different than a tuple unpacking assignment: a, b = 1, 2 a, b
(1, 2) [a, b] = [1, 2] a, b
(1, 2)
In both instances the names a and b are both mapped to 1 and 2 so why are there
two different forms?
Thanks for any answers.
--
Norvell Spearman 5 1443
> [spam, ham] = ['yum', 'YUM'] I don't see how this is any different than a tuple unpacking assignment:
>>> a, b = 1, 2
It's not different. They are ways of writing the same thing.
Raymond Hettinger
Raymond Hettinger wrote: [spam, ham] = ['yum', 'YUM']
I don't see how this is any different than a tuple unpacking assignment:
>>> a, b = 1, 2
It's not different. They are ways of writing the same thing.
TMTOWTDI, after all. :)
Raymond Hettinger wrote: It's not different. They are ways of writing the same thing.
Lutz and Ascher have tuple and list assignment as separate entries in their
assignment statement forms table so I was expecting there to be some
difference; thanks for setting me straight.
--
Norvell Spearman
Jeffrey Schwab wrote: TMTOWTDI, after all. :)
A bit ironic that that's the official motto of Perl, don't you think?
--
Norvell Spearman
Norvell Spearman <no*****@stenocall.com> writes: Lutz and Ascher have tuple and list assignment as separate entries in their assignment statement forms table so I was expecting there to be some difference; thanks for setting me straight.
In older Python versions there was a difference between list unpacking
and tuple unpacking. The former would only work with lists and the
latter with tuples. With Python 1.5, both were unified into a more
general sequence unpacking, but for backwards compatibility both
syntaxes were kept.
Bernhard
--
Intevation GmbH http://intevation.de/
Skencil http://skencil.org/
Thuban http://thuban.intevation.org/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Santanu Chatterjee |
last post by:
Hello everybody,
I am very new to python. I have a query about
list in python.
Suppose I have a list
a = ,5,6,7,,11,12]
I want to know if there is any simple python
facility available that...
|
by: Philippe C. Martin |
last post by:
Hi,
I'm looking for an easy algorithm - maybe Python can help:
I start with X lists which intial sort is based on list #1.
I want to reverse sort list #1 and have all other lists sorted...
|
by: C++fan |
last post by:
Suppose that I define the following class:
class example_class{
public:
example_class();
void funtion_1();
void function_2();
protected:
|
by: Darryl B |
last post by:
I can not get anywhere on this project I'm tryin to do. I'm not
expecting any major help with this but any would be appreciated. The
assignment is attached. The problem I'm having is trying to set...
|
by: Barry Hynes |
last post by:
G'Day folks,
Have been working on this problem for quite some time and still no farther
ahead. :(
Here is my problem...bare with me i am very green :)
I have to implement a Safe List,...
| |
by: Steven Watanabe |
last post by:
I know that the standard idioms for clearing a list are:
(1) mylist =
(2) del mylist
I guess I'm not in the "slicing frame of mind", as someone put it, but
can someone explain what the...
|
by: Ville Vainio |
last post by:
I tried to clear a list today (which I do rather rarely, considering
that just doing l = works most of the time) and was shocked, SHOCKED
to notice that there is no clear() method. Dicts have it,...
|
by: Christian Christmann |
last post by:
Hi,
reading the output of gprof for one of my projects, I found that the
STL list assignment operator consumes a larger fraction of the
program's execution time. The exact entry in gprof's...
|
by: David Bilsby |
last post by:
All
Apologies for cross posing this but I am not sure if this is a VC 8 STL
bug or simply an invalid use of the iterator.
I have a PCI card access class which basically abstracts a third party...
|
by: Taras_96 |
last post by:
Hi everyone,
The FAQ at http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.6
states that:
"Consider the following constructor that initializes member object x_
using an initialization...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |