Search code examples
pythonshellenvironment-variablesglobal-variables

environmental variables vs. global variables


I am pretty new to shell scripting and python. While I was reading the materials, I saw the term "environmental variable" in shell and "global variable" in python. I kind of feel these two words mean the same but not sure. Can anyone explain their difference in more details.

Thank you in advance.


Solution

  • They don't mean the same. "global" is a programming language idea, "environment variable" is an operating system idea. So, they're not really related, and conceptually quite different!

    Since you now know that, and both terms are easily researchable ("environment variable" on wikipedia, global variable on the Python.org language tutorial), I'm not going to write an introduction into two completely unrelated topics here – I simply couldn't put it any better.

    Note that as Python beginner, you will not have to deal with explicitly global variables often. In fact, global is usually a keyword you should avoid, it often is a sign that you forgot to correctly think of what goes in and out of a function.