Skip to main content
Chemistry LibreTexts

4.6: Boolean (atomic)

  • Page ID
    469569
  • \( \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}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    Boolean Data Types

    Boolean expressions are expressions that can result in only one of two possible answers, true or false. These results in a special data type, where Boolean values associate a value of zero for a false statement and a value of 1 for a true statement. Boolean algebra had it origins in the 1800's and George Boole's book "The Mathematical Analysis of Logic, Being an Essay Towards a Calculus of Deductive Reasoning" that is available through the Gutenberg Project. Boolean data types are essential to computational reasoning because they can result in logical reasoning based outcomes based on the truth (or falseness) of a statement or condition in terms of binary code. For example, you could have an if statement branch your programming logic based on the conditions resulting from a comparison operator that decides if one number is greater than another.

    clipboard_e7271918f8759a76b9cb64fb783c4241e.pngFigure \(\PageIndex{1}\): In binary code a value of zero equates to a false statement and a value of 1 equates to a true statement. (Belford cc 0.0)

    There are several types of operators that evaluate to boolean values (true or false) and these include Boolean Operators and Comparison Operators

    Boolean Operators

    Boolean operators AND, OR and NOT are used in search engines and in python they evaluate to values of the boolean data type.  These can be understood by the Truth Table and these can be applied to nonmathematical data types like strings (words).  

    AND

    In an AND condition both statements must be true for the result to evaluate to true.  For example, if you have an exam and a calculator you can use the calculator on the exam, but if you have an exam and no calculator, or a calculator and no exam, or neither a calculator or an exam, you can't use a calculator on an exam.

    clipboard_e11816880f4fcd6c7675ef2166bbb9a28.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)
    have_calculator=True
    have_exam = True
    print(f"I have calculator {have_calculator} \n and I have exam {have_exam} \n so can I use calculator on exam? {have_calculator and have_exam}\n")
    
    have_calculator=False
    have_exam = True
    #print("Can I use calculator on exam?",have_calculator and have_exam)
    print(f"I have calculator {have_calculator} \n and I have exam {have_exam} \n so can I use calculator on exam? {have_calculator and have_exam} \n")
    
    
    have_calculator=True
    have_exam = False
    #print("Can I use calculator on exam?",have_calculator and have_exam)
    print(f"I have calculator {have_calculator} \n and I have exam {have_exam} \n so can I use calculator on exam? {have_calculator and have_exam} \n")
    
    
    have_calculator=False
    have_exam = False
    #print("Can I use calculator on exam?",have_calculator and have_exam)
    print(f"I have calculator {have_calculator} \n and I have exam {have_exam} \n so can I use calculator on exam? {have_calculator and have_exam}")
    
    Hello world!

     

    OR

    For an OR value to be true either one or both conditions are true, and this only evaluates false if both conditions are not met.

    clipboard_ec08ae34a9473c78cbc866b55a24dd2a4.pngFigure \(\PageIndex{1}\): Copy and Paste Caption here. (Copyright; author via source)
    have_pen = True
    have_pencil = True
    print(f"I have a pen {have_pen} \n and I have a pencil {have_pencil} \n so can I write on paper? {have_pen or have_pencil}\n")
    
    have_pen = False
    have_pencil = True
    print(f"I have a pen {have_pen} \n and I have a pencil {have_pencil} \n so can I write on paper? {have_pen or have_pencil}\n")
    
    have_pen = True
    have_pencil = False
    print(f"I have a pen {have_pen} \n and I have a pencil {have_pencil} \n so can I write on paper? {have_pen or have_pencil}\n")
    
    have_pen = False
    have_pencil = False
    print(f"I have a pen {have_pen} \n and I have a pencil {have_pencil} \n so can I write on paper? {have_pen or have_pencil}\n")
    
    Hello world!

     

    NOT

    The NOT operator negates a boolean value.  This is a little confusing, but it takes a true statement and makes it false.  For example we can say if it is sunny, then it is not cloudy.  This should not be confused with the not equal (!=) comparison operator, that also evaluates to a Boolean value.

    is_sunny = True
    is_cloudy = not is_sunny
    print("Is it sunny",is_sunny)
    print("Is it cloudy", is_cloudy)
    Hello world!

    Comparison Operators

    There are 8 common comparison operators

    symbol meaning  symbol meaning
    < less than <= less than or equal
    > greater than >= greater than or equal
    == equal != not equal
    is object identity is not negated object identity

    Note that in python the equal sign [=] is the assignment operator and assigns a value to a variable.

     


    This page titled 4.6: Boolean (atomic) is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?