+ 1
how dose the variable x,y get defined as a,b without declaring it such as a=x b= y
5 ответов
+ 2
I see the above code as declaration. This is because python unlike JavaScript for instance does not prepend var to declare variables.
In JavaScript:
var a = x
var b = y
In python:
a = x
b = y
The = operator is an assignment operator so python is smart to understand that, the item on the right should be a value to be put into the container of the item on the left, variable
+ 1
Python is cool so you can also the following:
a,b = x,y
+ 1
Using the Functions as Objects lesson. In that lesson x and y are variables of multiply (the function) when operation (the variable) is assigned to multiply (the function) operation = multiply then all atributes of multiply now apply to operation. Operation takes the variables of a and b already defined as 4, 7 and in the operation instance of multiply 4 and 7 now take the place of x and y.
0
thanks that makes sense
0
they cant