# [Tutor] Question

Alan Gauld alan.gauld at yahoo.co.uk
Sun Dec 10 04:32:38 EST 2017

On 10/12/17 05:48, Khabbab Zakaria wrote:
> I am working on a program where I found the line:

> x,y,z = np.loadtext('abcabc.txt', unpack= True, skiprows =1)

> What does the x, y, z thing mean?
> What does the unpack= True mean?

They are related. unpacking is a feature of Python whereby a collection
of values can be assigned to individual variables in one statement.

Consider a list of numbers:

nums = [1,2,3]

we can unpack those 3 values into separate variables like so

x,y,z = nums

This is equivalent to:

x = nums[0]
y = nums[1]
z = nums[2]

So in your example the numpy function returns some
kind of collection of 3 values which are unpacked
into x,y and z exactly as we did with nums above.

I assume the unpack=True argument simply controls
the output of the function such that unpacking is
possible, but I'm not familiar with it so cannot
be sure.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos