Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7009071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:48:57+00:00 2026-05-27T21:48:57+00:00

Suppose we have: >>> x = 1 >>> y = 2 If we try

  • 0

Suppose we have:

>>> x = 1
>>> y = 2

If we try assigning both values at once like so:

>>> x, y = y, x+y
>>> x
2
>>> y
3

Then we get a different result than if we did the assignments separately:

>>> x = 1
>>> y = 2
>>> x = y
>>> y = x+y
>>> x
2
>>> y
4

Why does this happen?


See also Multiple assignment semantics regarding the effect and purpose of parentheses on the left-hand side of a multiple assignment.

See also Understand Python swapping: why is a, b = b, a not always equivalent to b, a = a, b? for more complex cases, where the order of assignment matters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:48:58+00:00Added an answer on May 27, 2026 at 9:48 pm

    In an assignment statement, the right-hand side is always evaluated fully before doing the actual setting of variables. So,

    x, y = y, x + y
    

    evaluates y (let’s call the result ham), evaluates x + y (call that spam), then sets x to ham and y to spam. I.e., it’s like

    ham = y
    spam = x + y
    x = ham
    y = spam
    

    By contrast,

    x = y
    y = x + y
    

    sets x to y, then sets y to x (which == y) plus y, so it’s equivalent to

    x = y
    y = y + y
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a method like this: public void MyCoolMethod(ref bool scannerEnabled) { try
Suppose I have something like this : try code_that_fails() catch _:_ -> ..... How
Suppose I have codes like these public void Upload (Picture picture) try { //ps
Suppose I have codes like these public void Upload (Picture picture) try { //ps
Suppose you have code like this: Result.X := ACustomMemo.Perform(EM_LINEFROMCHAR, -1, 0); The Windows API
Background: Suppose I have the following obviously-incorrect PHP: try{ $vtest = ''; print(array_pop($vtest)); }catch(Exception
Suppose you have 2 different ASP.NET applications in IIS. Also, you have some ASCX
I am really bad explaining but I'll try. Suppose I have with the following
Suppose I have a class like the following: public class Stage { public int
Let's suppose we have such code: int x = 0; try { try {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.