Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for answer to How can I use a global variable in a function? by Jeff S

Current License: CC BY-SA 4.0

Post Revisions

20 events
when toggle format what by license comment
May 17, 2025 at 22:11 comment added BlackJack @julaine Yes, there's a conclusion to be drawn here. πŸ˜‰ Nevertheless MyGlobal is still wrong because that would be a class name per Python naming conventions and the literal value 5 isn't a class.
May 16, 2025 at 7:58 comment added julaine @BlackJack you are saying this on a Q/A about how to modify a global variable.
Feb 26, 2025 at 20:19 review Suggested edits
Feb 28, 2025 at 16:57
S May 4, 2023 at 8:08 history suggested user CC BY-SA 4.0
Make improvement
May 4, 2023 at 7:17 review Suggested edits
S May 4, 2023 at 8:08
Mar 25, 2023 at 14:44 comment added BlackJack @streamofstars Yes and there are only constants at that level. Nobody in their right mind wants global variables/state. πŸ˜‰
Mar 23, 2023 at 20:26 comment added streamofstars @BlackJack Unless this changed between 2018 and 2023, as per PEP8 to which you linked yourself, it's the constants that are supposed to be uppercase. Global variables are clearly described in PEP8 as to follow the same convention as functions, which are lowercase.
Jun 13, 2022 at 10:11 history edited Georg Plaz CC BY-SA 4.0
PEP8: snake_case for global variable names and ideally with underscore to keep it module private https://peps.python.org/pep-0008/#global-variable-names
Jun 13, 2022 at 10:00 history edited Georg Plaz CC BY-SA 4.0
PEP8: snake case for global variable names (as they are named like functions, which are snake_case) https://peps.python.org/pep-0008/#global-variable-names
Jan 25, 2018 at 17:46 comment added BlackJack @Vassilis: It is common to upper case all letters: MY_GLOBAL = 5. See the Style Guide for Python Code.
Jan 25, 2018 at 17:43 comment added BlackJack @watashiSHUN: The namespace decision does happen at compile time. Deciding that x is local is different from checking at runtime if the local name was bound to a value before it is used the first time.
Jan 24, 2018 at 11:55 comment added Vassilis It is common to use a capital letter for global variables like MyGlobal = 5
Oct 12, 2015 at 22:36 comment added watashiSHUN You mentioned that the namespace decision happens at compile time, I don't think it is true. from what I learn python's compilation only checks for syntax error, not name error try this example def A(): x+=1, if you don't run it, it will not give UnboundLocalError, please verify thank you
S Mar 16, 2015 at 18:01 history suggested Michael come lately CC BY-SA 3.0
demarcate inline function and variable names.
Mar 16, 2015 at 17:37 review Suggested edits
S Mar 16, 2015 at 18:01
S Apr 28, 2014 at 22:41 history suggested Urda CC BY-SA 3.0
Use proper Python comment, so users can cute and paste
Apr 28, 2014 at 22:34 review Suggested edits
S Apr 28, 2014 at 22:41
S Jan 22, 2013 at 6:00 history suggested Honest Abe CC BY-SA 3.0
added missing word // added link about garbage collection
Jan 22, 2013 at 5:55 review Suggested edits
S Jan 22, 2013 at 6:00
Jan 8, 2009 at 9:19 history answered Jeff Shannon CC BY-SA 2.5
toggle format

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /