Skip to Content
Pandas for Everyone: Python Data Analysis, First Edition
book

Pandas for Everyone: Python Data Analysis, First Edition

by Daniel Y. Chen
December 2017
Beginner to intermediate
410 pages
12h 45m
English
Addison-Wesley Professional
Content preview from Pandas for Everyone: Python Data Analysis, First Edition

Q. Multiple Assignment

Multiple assignment in Python is a form of syntactic sugar. It provides the programmer with the ability to express something succinctly while making this information easier to express and to be understood by others.

As an example, let’s use a list of values.

l = [1, 2, 3]

If we wanted to assign a variable to each element of this list, we can subset the list and assign the value.

a = l[0] b = l[1] c = l[2] print(a)

1

print(b)

2

print(c)

3

With multiple assignment, if the statement to the right is some kind of container, we can directly assign its values to multiple variables on the left. So, the preceding code can be rewritten as follows:

a1, b1, c1 = l print(a1)

1

print(b1)

2

print(c1)

3

Multiple assignment is often used ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pandas for Everyone: Python Data Analysis, 2nd Edition

Pandas for Everyone: Python Data Analysis, 2nd Edition

Daniel Y. Chen

Publisher Resources

ISBN: 9780134547046Purchase book