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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:06:11+00:00 2026-05-14T17:06:11+00:00

Please see the following code: def good(): foo[0] = 9 # why this foo

  • 0

Please see the following code:

def good():
  foo[0] = 9         # why this foo isn't local variable who hides the global one

def bad():
  foo    = [9, 2, 3] # foo is local, who hides the global one

for func in [good, bad]:
  foo = [1,2,3]

  print('Before "{}": {}'.format(func.__name__, foo))
  func()
  print('After  "{}": {}'.format(func.__name__, foo))

The result is as below:

# python3 foo.py
Before "good": [1, 2, 3]
After  "good": [9, 2, 3]
Before "bad" : [1, 2, 3]
After  "bad" : [1, 2, 3]
  • 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-14T17:06:12+00:00Added an answer on May 14, 2026 at 5:06 pm

    Because you’re not setting foo, you’re getting something in foo (foo[0] to be exact).

    In bad you create a new variable foo. In good you do something like foo.set(0, 9) (set item 0 to value 9). Which is using a variable, and not defining a new name.

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

Sidebar

Ask A Question

Stats

  • Questions 536k
  • Answers 536k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer DateTime.Parse may unexpectedly throw FormatException because it is locale-dependent. From… May 17, 2026 at 1:22 am
  • Editorial Team
    Editorial Team added an answer I'm not sure which values you wanted to extract from… May 17, 2026 at 1:22 am
  • Editorial Team
    Editorial Team added an answer This is clearly documented in the ?transformBy help page, and… May 17, 2026 at 1:22 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Having a bit of an issue please see the following code: window.onload = function
Please see the the following http://valogiannis.com/recent/ .I have a webpage and when user click
In the following code you'll see a simple lexer that conforms to the following
Please have a look to the following code: <?php $nomeDominio=''; if (isset($_GET['infoDominio'])) { $nomeDominio
I have the following code that will check to see if the div text
So Im trying to make an object dynamically, please see below code from my
*Edit: Please see my answer below for the solution. Is there any danger in
Example dump from the list of a directory: hello:3.1 GB world:1.2 MB foo:956.2 KB
Suppose you have the following situation #include <iostream> class Animal { public: virtual void
I've encountered a very odd issue in regards to session variables and local variables

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.