I find a strange statement when I'm reading PIL document.
In 1.1.6 and later, load returns a pixel access object that can be used to read and modify pixels. The access object behaves like a 2-dimensional array, so you can do:
pix = im.load() print pix[x, y] pix[x, y] = value
What does pix[x, y]
mean here? It's not slicing syntax because ,
used rather than :
.
It means that the function you have called returns an iterable, and the index 0 of the iterable is assigned to x and the index 1 is assigned to y. This is called tuple unpacking .
pix[x, y]
is the same as
t = x, y
pix[t]
or
t = (x, y)
pix[t]
or
pix[(x, y)]
What you're seeing is a tuple literal inside an item-getting expression, in the same way that I can nest other expressions such as l[1 if skip else 0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With