Reputation: 33
I'm a newbie of python.
I couldn't understand the usage of pix = im_pixel[j, i]
.
In []
, there is a comma (,
).. Is this the right syntax?
Upvotes: 0
Views: 95
Reputation: 15934
im_pixel[j,i]
just means that the key being passed to im_pixel
is the tuple j, i
. This will call whatever im_pixel
has defined for __getitem__
with this tuple as a parameter. What this does will be defined by the type of im_pixel
For example if im_pixel
was a dictionary it would fetch the key (j, i)
. Anything immutable and hashable is allowed to be a dictionary key in Python and a tuple is both immutable and hashable so this would be allowed for a dictionary type. As Duncan mentions the whole key must be immutable, so the individual elements of the tuple must also be immutable as well.
Upvotes: 2