Skip to main content
Engineering LibreTexts

3.2: Environments and Variables

  • Page ID
    39349
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    A data analysis program – of which we will write many in this course – makes use of an environment as it runs. “Environment” just means “all the data that is currently in view, and which the program can access.”1 The environment consists of variables, each of which (usually) has a name and a value. For example, we might have a variable named age whose value is 21, and a variable named slogan whose value is "Finger lickin’ good".

    Each variable in the environment must have a distinct name (i.e., no two variables can share the same name). Also, importantly, the reason these building blocks are called “variables” is that their value can change as the program executes. Although we may initially create an age variable with the value 21, later on in the program the variable’s value might change to 22, or 50, or 0. The variable’s name never changes, though.

    1Confusingly, this use of the term “environment” is different from the term “programming environment” I introduced on p.9.


    This page titled 3.2: Environments and Variables is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Stephen Davies (allthemath.org) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?