Skip to main content
Chemistry LibreTexts

8.12: Subscripts and Superscripts

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

    One way to create subscripts and superscripts in strings is to use unicode and concatenate.  The following table gives unicode subscript and superscript values that you may often needc

    character 0 1 2 3 4 5 6 7 8 9 + -
    superscript U2070 U00B9 U00B2 U00B3 U2074 U2075 U2076 U2077 U2078 U2079 U207A U207B
    subscript U2080 U2081 U2082 U2083 U2084 U2085 U2086 U2087 U2088 U2089 U208A U208B

     

    #We will now use concatenation to create the formula for sulfuric acid.
    sulfuric_acid="H"+"\u2082"+"SO"+'\u2084'
    sulfate_ion = "SO"+"\u2084\u207B\u00B2"
    print(sulfuric_acid, "and", sulfate_ion)
    Hello world!

    Note, we can make variables for the unicode

    s2,s3,s4,s5,s6,s7,s8,s9="\u2082","\u2083","\u2084","\u2085","\u2086",\
                             "\u2087","\u2088","\u2089"
    ammonium_phosphate="(NH"+s4+")"+s3+"PO"+s4
    print(ammonium_phosphate)
    
    Hello world!
    Exercise \(\PageIndex{1}\)

    You want the following code to display

    clipboard_e417175bcb8e19298ab9ea64c167335aa.pngFigure \(\PageIndex{1}\): Alter the code below to produce this output

    The following code does not work.  comment out the print statement and uncomment the lines above and below it, and then complete the expression for x so that the code works.

    #the following line assigns subscripts to the varibles using unicode   
    s2,s3,s4,s5,s6,s7,s8,s9="\u2082","\u2083","\u2084","\u2085","\u2086",\
                             "\u2087","\u2088","\u2089"
    #x=
    n_nonane="CH"+s3+7*"(CH"+s2+")"+"CH"+s3
    #n_nonane="CH"+s3+7*x+"CH"+s3
    print(n_nonane)
    Hello world!

     

    Answer

    x = "(CH"+s2+")"

     

     


    This page titled 8.12: Subscripts and Superscripts is shared under a not declared license and was authored, remixed, and/or curated by Robert Belford.

    • Was this article helpful?