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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:50:36+00:00 2026-05-24T07:50:36+00:00

ok, noob question I had this code list = [‘random’, ‘set’, ‘of’, ‘strings’] for

  • 0

ok, noob question

I had this code

           list = ['random', 'set', 'of', 'strings']
           for item in list:
               item.replace('a','b')

           print list

the output doesn’t show the replacement unless I change the code to this

            list = ['random', 'set', 'of', 'strings']
            for item in list:
                item = item.replace('a','b')

            print list

so my question is what exactly is going on? why doesn’t the first example automatically assign?

  • 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-24T07:50:38+00:00Added an answer on May 24, 2026 at 7:50 am

    The method is simply returning the new value, it does not modify the existing one.

    There is no set rules that specify that all or no methods will do this, you will have to check the documentation for each one to know specifically what it does and what to expect.

    Lots of functions are like that.

    Take this:

    a = 1
    b = 2
    c = Add(a, b)
    

    would you expect a or b to have new values at this point? This is the same exact thing.

    Now, having said that, there is another problem with your code. Under no circumstances will that list actually change.

    Why? Because you’re not updating the list, you’re updating item.

    And item is a “copy” of the value in the list. This is not strictly correct, but it suffices for this answer (learn about references for more information.)

    In other words, if you change your two examples to this:

    list = ['random', 'set', 'of', 'string']
    for item in list:
        item.replace('a','b')
        print item
    

    vs.

    list = ['random', 'set', 'of', 'string']
    for item in list:
        item = item.replace('a','b')
        print item
    

    then you will see a difference.

    Answer to follow-up question in comment: If you do not store the result anywhere, it is simply lost. Think of it this way: You call up your friend and ask what time it is on his watch. He says “10:45”, and you respond with “actually I don’t care click.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that this is a probably a noob-ish question, but I've had no
a noob question here: any ideas why this code: UIViewController* popoverviewController = [[UIViewController alloc]init];
Noob question... I'm trying to display a List in a textbox... unfortunately, my code
This is a noob question from someone who hasn't written a parser/lexer ever before.
I know this may be a noob question, but it's bugging the heck out
This is a bit of noob question - I'm still fairly new to C#
This is probably a noob question that I will get slated for but here
Noob question. I have this situation where I have these objects: class Address {
another noob question regarding F#. If I have the following code... let ExeC =
Sorry if this is a stupid noob question. I'm doing a very small project

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.