Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clarity on global variables
#1
I have some code in which I have global variables which are accessed within functions but only in some cases they are recognized. I read online that this can be overcome by adding the line global <var> at the top of the functions that access the variable, but why is it that other variables declared globally are recognized by the same function? Does the type of the variable matter - in the case I am dealing with the variable that is not recognized is an integer while the recognized ones are strings.

Thanks for any help
Reply


Messages In This Thread
Clarity on global variables - by JonWayn - Nov-25-2022, 10:44 AM
RE: Clarity on global variables - by DeaD_EyE - Nov-25-2022, 11:29 AM
RE: Clarity on global variables - by JonWayn - Nov-26-2022, 12:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand global variables 357mag 5 1,139 May-12-2023, 04:16 PM
Last Post: deanhystad
  Global variables or local accessible caslor 4 1,037 Jan-27-2023, 05:32 PM
Last Post: caslor
  global variables HeinKurz 3 1,160 Jan-17-2023, 06:58 PM
Last Post: HeinKurz
  I need some clarity on the use of the open command JonWayn 11 2,421 Nov-08-2022, 11:46 PM
Last Post: JonWayn
  Global variables not working hobbyist 9 4,750 Jan-16-2021, 03:17 PM
Last Post: jefsummers
  Global vs. Local Variables Davy_Jones_XIV 4 2,667 Jan-06-2021, 10:22 PM
Last Post: Davy_Jones_XIV
  Global - local variables Motorhomer14 11 4,278 Dec-17-2020, 06:40 PM
Last Post: Motorhomer14
  Question regarding local and global variables donmerch 12 5,118 Apr-12-2020, 03:58 PM
Last Post: TomToad
  local/global variables in functions abccba 6 3,450 Apr-08-2020, 06:01 PM
Last Post: jefsummers
  Where to put the global keyword when assigning variables outside a function? new_to_python 8 3,044 Feb-09-2020, 02:05 PM
Last Post: new_to_python

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020