I'm not sure how to ask this question properly cause I'm trying to understand something I don't understand yet and therefore I don't know the right terminology to use, but I came across this code snippet in a YouTube tutorial regarding PIL here.
Question
Could somebody please explain what the last line means? I'm guessing it is a Python style of declaring variables I am not familiar with yet and I dont know what it is called so I can't look it up.
import Image
filename = "py.png"
image = Image.open(filename)
size = width, height = image.size
What I've Tried
I've tried to break down the logic of the last line but it doesn't make sense to me:
# assign value of width to size variable?
size = width
# assign value of image.size to height variable?
height = image.size
The problems I see with this are:
width
is not defined.image.size
represents the images dimensions ie(512,512)
so that doesn't seem like it would be an appropriate value forheight
.
I'm sure this is very simple, I just don't get it yet.
Solution
I think I figured it out by running the following:
So essentially what the code in the original post is saying is:
Which means:
"The variable
size
is a tuple made of two values (width
andheight
) and their values are512
and512
resp".The mechanics of it haven't really sunk in yet, but good enough for now.