Let $K=\mathbb{Q}(\sqrt{2})$. I want to calculate $|\mathcal{O_K}/ \mathfrak{a}|$ in sage with $\mathfrak{a}=3\mathbb{Z}$. This code:
sage: K.<sqrt(2)>=NumberField(x^2-2)
sage:01=K.order(sqrt(2))
OK=ring_ of _ integers()
sage: O1.index_in(OK)
does not really work.
You mean $\mathfrak{a} = (3) = 3\mathcal{O}_K$, because $3\mathbb{Z}$ is not an ideal in $\mathcal{O}_K$ (it is not closed under multiplication by $\sqrt{2}$).
This index $[\mathcal{O}_K:\mathfrak{a}] =|\mathcal{O}_K/\mathfrak{a}|$ is also called the norm of the ideal $\mathfrak{a}$:
Since $\mathfrak{a}=(3)$ is prime in $\mathcal{O}_K$ (hence maximal, because $\mathcal{O}_K$ is a Dedekind domain), the quotient $\mathcal{O}_K/\mathfrak{a}$ is a field called the residue field, and we can also get its order: