This hasn't been a problem before, but before I continue my programming adventures I need clarification in the differences between Global Variables, Local variables, and constants.
From my understanding Global variables are initialized outside of everything, usually I put mine at the beginning of the code, after the heading. And its correct to put them in all caps right?
like GLOBAL_A for example
Local variables are initialized in functions and only used in those functions, pretty sure thats correct
Constants are what I'm confused with, they seem sort of like a global variable to me. I'm not sure where to initialize them and do I put them in all caps?
Or could it be that constants and global variables are the same thing?
Someone clear this up for me please.
A little confusion on variables in python
Page 1 of 1
Global and constants
3 Replies - 1037 Views - Last Post: 08 May 2010 - 12:29 PM
Replies To: A little confusion on variables in python
Re: A little confusion on variables in python
Posted 05 May 2010 - 01:37 PM
You are right globals are outside of everything. Now the thing about constants is that they are constant (they never ever change) That is the difference between globals and constants, globals can change and constants can not. Yes I would say to put constants in all caps and at the top of the code.
Page 1 of 1