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

  • SEARCH
  • Home
  • 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 8225669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:29:30+00:00 2026-06-07T15:29:30+00:00

I was reading the assignment statements in the Python docs ( http://docs.python.org/reference/simple_stmts.html#assignment-statements ). In

  • 0

I was reading the assignment statements in the Python docs ( http://docs.python.org/reference/simple_stmts.html#assignment-statements).

In that it is quoted that:

If the target is a target list enclosed in parentheses or in square brackets: The object must be an iterable with the same number of items as there are targets in the target list, and its items are assigned, from left to right, to the corresponding targets.

After reading it, I thought of writing a sample like this:

a = 5
b = 4
a, b = a + b, a
print a, b

My assumption was that a and b both should have the value of 9.

However, I am proven wrong. ‘a’ has the value of 9 and ‘b’ has the value of 5.

Can some one help me understand this better? Why the older value of ‘a’ is assigned rather than the new one? As per the docs, a’s value will be assigned first right? Am I missing something?

  • 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-06-07T15:29:32+00:00Added an answer on June 7, 2026 at 3:29 pm

    All the expressions to the right of the assignment operator are evaluated before any of the assignments are made.

    From the Python tutorial: First steps towards programming:

    The first line contains a multiple assignment: the variables a and b simultaneously get the new values 0 and 1. On the last line this is used again, demonstrating that the expressions on the right-hand side are all evaluated first before any of the assignments take place. The right-hand side expressions are evaluated from the left to the right.

    Emphasis mine.

    Your code is functionally equivalent to the following:

    a, b = 5 + 4, 5
    print a, b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading manual about Sling http://sling.apache.org/site/46-line-blog.html added folder blog and blog.html to destination: \launchpad\content\src\main\resources\content\ but
I am working on an assignment that deals with reading data from a text
I was reading this http://en.wikipedia.org/wiki/C%2B%2B0x#Modification_to_the_definition_of_plain_old_data It mentions trivial default constructor, trivial copy constructor, copy
In my assignment i have a problem with reading a file. See the following
Reading the docs, I'd expect $(#wrap2).remove(.error) to remove all .error elements from #wrap2 .
Reading the MCIMX50 Application Processor Reference Manuals on page 1368 (Section 33.3) there is
For my homework assignment, I have a network of Nodes that are passing messages
I've been reading some contradicting articles in regards whether move constructors/assignment is allowed to
I'm reading programming best practices and it is said that when creating a function
I am working on an assignment that only allows use of low-level I/O (read(),

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.