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 7668879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:28:08+00:00 2026-05-31T15:28:08+00:00

I am a python beginner. Recently I saw this snippet of code: >>> words

  • 0

I am a python beginner. Recently I saw this snippet of code:

>>> words = ['I', 'turned', 'off', 'the', 'spectroroute']
>>> words[2], words[3], words[4] = words[3], words[4], words[2]
>>> words
['I', 'turned', 'the', 'spectroroute', 'off']

I am confused about the 2nd line. It seems tuples are used but I don’t understand why the sequence of the list is changed to the result?

It looks like the 2nd line is doing this:

>>> tmp = words[2]
>>> words[2] = words[3]
>>> words[3] = words[4]
>>> words[4] = tmp

My question is: why does the code in 2nd line change the list as the result?

Thanks in advance

  • 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-31T15:28:10+00:00Added an answer on May 31, 2026 at 3:28 pm

    You are pretty much correct. Its creating a tuple on the right side (in memory) and then unpacking its values into the original list, thus overwriting the previous indexes. Thats why you dont need a tmp variable, since its happening in memory.

    Its similar to this concept:

    a, b, c = (1, 2, 3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginner in Python, teaching myself off of Google Code University. I had
I've got a question related to a beginner Python snippet I've written to introduce
Python beginner >>> import oauth2 Traceback (most recent call last): File , line 1,
I'm trying to get simple code working, unfortunately I'm a python beginner. My script
I'm an absolute beginner using IDLE (Python 2.6.4) to learn the basics. I recently
Beginner in python, but been programming for about 5 years now. I suspect I
I am beginner in python and facing this problem. So how i can break
I am a beginner at Python, and this is my first post, so don't
Python beginner here, so I apologize if this question has a simple answer. (I
I am still a python beginner. As a practice project I want to code

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.