Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
q.anisotropic_primes() gives the list of all primes $p$ (including $\infty$) such that $q$ is anisotropic over $\mathbb{Q}_p$. So by Hasse-Minkowski q is anisotropic over $\mathbb{Q}$ if and only if q.anisotropic_primes() is nonempty (note that in python for a list L, "if L" evaluates to False if L is empty and True otherwise).
For $n=2$, wouldn't any subset $X$ that intersects any line in finitely many points (but at least one) be a counterexample? There certainly exist such subsets that are not algebraic hypersurfaces.
@SugataMandal Two quadratic spaces are isomorphic if there is an isomorphism between the underlying vector spaces preserving the quadratic/bilinear form