Extending section of principal open subvariety Let $X$ be a variety (not necessarily affine) over an algebraically closed field.

Is it true, that for any global section $f \in \mathcal{O}_X(X)$ the natural morphism
  $\mathcal{O}_X(X)_f \to \mathcal{O}_X(D(f))$
  is an isomorphism?

Equivalently, we may ask:

For $g \in \mathcal{O}_X(D(f))$ arbitrary, is there a nonnegative integer $n$ such that $gf^n$ can be extended to a global section of $X$?

If necessary, we may further assume that $D(f)$ is affine.
 A: Yes, and in fact something much stronger is true:

Lemma: (Quasi-Compact Quasi-Separated Lemma, or simply QCQS lemma)
Let $X$ be a quasi-compact, quasi-seperated scheme and $f \in \Gamma(X,\mathcal{O}_X)$. Then the natural map $\Gamma(X,\mathcal{O}_X)_f \rightarrow\Gamma(X_f,\mathcal{O}_X)$ is an isomorphism. (Here $X_f = D(f) :=\{x \in X : f_x\not\in\mathfrak{m}_{X,x}\}$.

And so this holds in particular for varieties (over any field) since a variety is separated (whence quasi-seperated) and finite type (whence quasi-compact).
The proof is quite short:
Take $U_i \cong \operatorname{Spec}(A_i)$ a finite open affine cover of $X$, and then, since by quasi-separatedness $U_i \cap U_j$ is quasi-comapct, we may further cover this intersection by open affine sets $U_{ijk} \cong \operatorname{Spec}(A_{ijk})$. Taking sections of these open subsets, and recalling the defining properties of a sheaf gives the following exact sequence:
$$0 \rightarrow \Gamma(X,\mathcal{O}_X) \rightarrow \prod_{i}\Gamma(U_i,\mathcal{O}_X) \rightarrow \prod_{ij}  \Gamma(U_i\cap U_j,\mathcal{O}_X)$$
But since we have a cover of $U_i\cap U_j$, we have an injection $\prod_{ij}\Gamma(U_i\cap U_j,\mathcal{O}_X)\rightarrow \prod_{ijk}\Gamma(U_{ijk})$. By adding on this map to the end of the above exact sequence, and identifying the sections of affine schemes with the underlying ring, we get another exact sequence:
$$0 \rightarrow \Gamma(X,\mathcal{O}_X) \rightarrow \prod_{i}A_i \rightarrow \prod_{ijk}  A_{ijk}$$
But now localisation is exact, giving a third exact sequence:
$$0 \rightarrow \Gamma(X,\mathcal{O}_X)_f \rightarrow (\prod_{i}A_i)_f \rightarrow (\prod_{ijk}  A_{ijk})_f$$
Now the crucial step: since these are finite products, they commute with localisation, giving another exact sequence:
$$0 \rightarrow \Gamma(X,\mathcal{O}_X)_f \rightarrow \prod_{i}(A_i)_f \rightarrow \prod_{ijk}  (A_{ijk})_f$$
(It is true that localisation commutes with arbitrary direct sums but not with arbitrary direct products. They key was that for finite indexes, sums and products are the same thing. Quasi-compactness and quasi-finiteness were essential in guaranteeing finiteness in the first and second products respectively, hence the name of the lemma).
To conclude, note that we also have an exact sequence:
$$0 \rightarrow \Gamma(X_f,\mathcal{O}_X) \rightarrow \prod_{i}\Gamma((U_i)_f,\mathcal{O}_X) \rightarrow \prod_{ij}  \Gamma((U_i)_f\cap U_j,\mathcal{O}_X)$$
Notice that the rightmost two parts of the final and penultimate exact sequences are actually the same rings with the same map between them (if you prefer, they are canonically isomorphic) so that we have described both $\Gamma(X,\mathcal{O}_X)_f$ and  $\Gamma(X_f,\mathcal{O}_X)$ as the kernel of the same map, hence the natural map $\Gamma(X,\mathcal{O}_X)_f \rightarrow \Gamma(X_f,\mathcal{O}_X)$ is an isomorphism.
