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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:23:27+00:00 2026-06-14T09:23:27+00:00

I was wondering why i was getting this error for adding a letter to

  • 0

I was wondering why i was getting this error for adding a letter to this string from a function.
local variable 'string' referenced before assignment

CODE

def update_string():
    string+='d'


string='s'

update_string()
  • 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-14T09:23:29+00:00Added an answer on June 14, 2026 at 9:23 am

    There is nowhere for the old ‘string’ to come from in the local scope of your function, so python assumes you’re talking about the one from the outer scope.

    Moreover, since strings are immutable the usual pattern is to create a new one and return it, so you might prefer to update your function interface to something more like:

    def update_string(str_in):
      return str_in + 'd'
    

    And then you would use it instead like:

    my_string = update_string(my_string)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I keep getting this error from the below code, was wondering if anyone
I am getting this error for every int in this section of code; if(choice==2)
I was wondering why I was getting this error: undefined reference to `vtable for
I am getting this error Uncaught SyntaxError: Unexpected token < from chrome but everything
Hey all i am wondering why i am getting this error with the following
I keep getting this error for a portion of my code. Traceback (most recent
I am getting this error with my c++ code: http://imageshack.us/photo/my-images/193/vcerror.png/ The only problem is
I am getting this error, and am wondering if anyone has any idea how
I was wondering why do I keep getting an error and unable to return
I am wondering if RegisterTypeForAjax isn't working correctly. I am getting the error noted

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.