Question about bra-ket notation for inner products in Quantum Mechanics I'm trying to understand the notation used to denote inner products in my introductory quantum physics textbook (Introduction to Quantum Mechanics, Griffiths). In section 6.1 where Griffiths introduces perturbation theory, he derives the first-order energy correction to be  $E_n^1=\langle\psi_n^0|H'|\psi_n^0\rangle,$ with a footnote linked to it that says

"In this context it doesn't matter whether we write $\langle\psi_n^0|H'\psi_n^0\rangle$ or $\langle\psi_n^0|H'|\psi_n^0\rangle$ (with the extra vertical bar), because we are using the wave function itself to "label" the state. But the latter notationis preferable, because it frees us from this specific convention.

What does the second vertical bar mean? I've been getting familiar with the inner product he defined earlier in the book, specifically  $\langle f|g\rangle\equiv\int_a^bf(x)^*g(x)dx,$ but I'm not sure what is meant when an operator is inserted in the middle enclosed in two vertical bars. What exactly is meant by $\langle f|Q|g\rangle?$ And when would $\langle f|Qg\rangle$ be different from $\langle f|Q|g\rangle?$
 A: $\newcommand{\bra}[1]{\left< #1 \right|}
\newcommand{\ket}[1]{\left| #1 \right>}
\newcommand{\bk}[2]{\left< #1 \middle| #2 \right>}
\newcommand{\bke}[3]{\left< #1 \middle| #2 \middle| #3 \right>}$
I shall be assuming that all vector spaces are finite-dimensional for purposes of simplicity. $\ket{f} \in V$ where $V$ is a vector space. $H^\prime$ is a linear operator; $$H^\prime\colon \, V \rightarrow V\\H^\prime\colon\,\ket{f}\rightarrow H^\prime\ket{f}.$$ $\ket{H^\prime f}$ is just another short-hand notation for $H^\prime\ket{f}$; $\ket{H^\prime f}\colon = H^\prime\ket{f}$. Thus, $\ket{H^\prime \psi_n^0} = H^\prime\ket{\psi_n^0}$.
$\bra{f} \in V^*$ where $V^*$ is the dual vector space to $V$. Elements of the dual space, called bras, are linear functionals, i.e. they are linear functions which take a vector from $V$ and assign it an element of the underlying field, a complex number in this case, all while respecting linearity. So, $\bra{f}$ is a function which acts on the elements of $V$ and produces a complex number. $\bra{f}(\ket{g}) = a$. The (finite-dimensional version of) Riesz representation theorem allows us to express this action as an inner product. Thus, $$\bra{f}(\ket{g}) = a = \langle\ket{f},\ket{g}\rangle \colon = \int_a^b f^* (x) g (x) \,\mathrm{d}x,$$ where $\langle \cdot, \cdot \rangle$ is the inner product. $\bk{f}{g}$ is just a short-hand notation for $\langle\ket{f},\ket{g}\rangle$; $\bk{f}{g} \colon = \langle\ket{f},\ket{g}\rangle$.
Note that we have taken the inner product of the kets $\ket{f}$ and $\ket{g}$, and not the "inner product of a bra and a ket". You will often find people colloquially saying the latter but I think that it is a bit sloppy to say that. Sure, the vector space and its dual are isomorphic (atleast in the finite-dimensional case), but this does not mean that they are equal. Inner product requires that both the entries come from the same vector space.
So $$\bke{\psi_n^0}{H^\prime}{\psi_n^0} = \bra{\psi_n^0}(H^\prime\ket{\psi_n^0}) = \bra{\psi_n^0}(\ket{H^\prime\psi_n^0}) = \bk{\psi_n^0}{H^\prime\psi_n^0} = \langle{\ket{\psi_n^0}}, \ket{H^\prime\psi_n^0}\rangle = \int_a^b {\psi_{n}^{0}}^{*}(x)H^\prime\psi_n^0(x).$$ The Wikipedia page on Bra–ket notation is nice. You can take a look at it if you want to.
Note: The vector space has been assumed to be finite-dimensional, but in quantum mechanics, more often than not, spaces turn out to be infinite-dimensional. In order to deal with them in a rigorous manner, functional analysis and other mathematical objects such as rigged Hilber spaces are needed. But the notation remains more or less the same, formally. If one is interested, Prof. Frederic Schuller provides an excellent, mathematically rigorous introduction to QM (lectures on YouTube, pdf notes).
