This following is a snippet of Python code I found that solves a mathematical problem. What exactly is it doing? I wasn’t too sure what to Google for.
x, y = x + 3 * y, 4 * x + 1 * y
Is this a special Python syntax?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
is the equivalent of:
EXCEPT that it uses the original values for x and y in both calculations – because the new values for x and y aren’t assigned until both calculations are complete.
The generic form is:
where a and b are expressions the values of which get assigned to x and y respectively. You can actually assign any tuple (set of comma-separated values) to any tuple of variables of the same size – for instance,
would also work, but
would not because the number of values in the right-hand tuple doesn’t match the number of variables in the left-hand tuple.