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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:17:04+00:00 2026-05-27T07:17:04+00:00

I have a very simple and maybe dumb question: Why does this work? def

  • 0

I have a very simple and maybe dumb question:

Why does this work?

def print_list():
    for student in student_list:
        print(student)

student_list = ["Simon", "Mal", "River", "Zoe", "Jane", "Kaylee", "Hoban"]
print_list()

The way I’ve come to know functions and arguments, the function print_list() shouldn’t recognize student_list since I didn’t assign it as an argument for the function.

  • 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-27T07:17:05+00:00Added an answer on May 27, 2026 at 7:17 am

    In Python, variables are created when you assign them. In your case, student_list is assigned in the global scope, so it is a global variable. (The global scope is the stuff that isn’t inside your function.)

    When Python encounters a variable inside a function that is not a local variable (that is, it was not passed in as an argument and was not assigned inside the function), it automatically looks for the variable in the global scope.

    If you are wondering what the purpose of the global statement is, since global variables are already visible inside functions: global allows you to reassign a global variable, and have it take effect globally. For example:

    def b():
        global a
        a = 5
    
    a = 4
    print(a)  # prints 4
    b()
    print(a)  # prints 5
    

    In most cases, you don’t need the global statement, and I would recommend that you don’t use it, especially until you are much more experienced in Python. (Even experienced Python programmers tend not to use global very much, though.)

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

Sidebar

Related Questions

I have a very simple question (I guess!) I used to work with Scriptaculous
maybe a very simple question, however I have no idea what I do wrong,
I have this strange, yet maybe very simple problem.. I have a timer1 in
I have maybe very very Simple Question: Where i can find documentation about expressions
I have what may be a very simple question. I want to process a
I have very simple select like this: SELECT * FROM table WHERE column1 IN
This may be a very dumb question but I can't seem to get it
Maybe I need more coffee this morning but here goes... I have a very
I have some problems with a very simple yacc/lex program. I have maybe forgotten
All, This question probably has a very simple answer - something I'm overlooking. But

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.