Skip to main content
Chemistry LibreTexts

2.16: Logical Operators

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

    Logical operators are also called Boolean operators and there are three types.  Now it needs to be realized that Boolean data types are true or false, and other operators (like comparison operators) produce Boolean output.

    Operator Description Example
    and returns True if both statements are true x<5 and x>1
    or returns True if either statement is true x<5 or x>1
    not returns True if result is false not(x<5 and x>1)

     

     

    or operator

    clipboard_e10a1d63a3ae3cb8f9bb9c6d538947d46.pngFigure \(\PageIndex{3}\): Truth table for OR statement (Belford cc 0.0)
    a=25
    x=(a>10 or a<5)
    print(a>10 or a<5)
    print(x)
    print(type(x))
    a=7
    y=(a>10 or a<5)
    print(y)
    print(type(y))
    Hello world!

     

    and Operator

    clipboard_e9ea8cc5ae56588302735a887915ecbaf.pngFigure \(\PageIndex{4}\): Copy and Paste Caption here. (Belford cc 0.0)
    a=25
    x=(a>5 and a<10)
    print(a>5 and a<10)
    print(x)
    print(type(x))
    a=7
    y=(a>5 and a<10)
    print(y)
    print(type(y))
    Hello world!

     

    not Operator 

    a=25
    print(not(a<10 and a>5))
    a=7
    print(not(a<10 and a>5))
            hello world
          

     

     


    This page titled 2.16: Logical Operators is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?