I have gotten a little confused about the notation regarding line bundles and their holomorphic sections on projective spaces, and subsequently projective varieties, as well as the meaning of $\mathcal{O}_X$. (My background is more in physics than algebraic geometry).
Let me start with line bundles on $\mathbb{P}^n$. These can be denoted by $\mathcal{O}_{\mathbb{P}^n}(k)$, for $k\in \mathbb{Z}$. There are various ways to arrive at this description, I think the standard method is to define the tautological line bundle -- where the fibre over $p\in\mathbb{P}^n$ is the line in $\mathbb{C}^n$ described by $p$ -- by $\mathcal{O}_{\mathbb{P}^n}(-1)$, and its dual, the hyperplane bundle, as $\mathcal{O}_{\mathbb{P}^n}(1)$, and then denote $$ \mathcal{O}_{\mathbb{P}^n}(k) = \mathcal{O}_{\mathbb{P}^n}(1)^{\otimes k}, \quad k\geq1 $$ $$ \mathcal{O}_{\mathbb{P}^n}(-k) = \mathcal{O}_{\mathbb{P}^n}(-1)^{\otimes k}, \quad k\geq1 $$
We can also denote by $\mathcal{O}_{\mathbb{P}^n} = \mathcal{O}_{\mathbb{P}^n}(0)$ the trivial bundle on $\mathbb{P}^n$, with the property that $\mathcal{O}_{\mathbb{P}^n}(k)\otimes\mathcal{O}_{\mathbb{P}^n}(-k) = \mathcal{O}_{\mathbb{P}^n}$. The tensor product then gives the space of line bundles the structure of an Abelian group, $Pic(\mathbb{P^n})=\mathbb{Z}$.
I believe that for a projective hypersurface $Y \subset \mathbb{P}^n$, ignoring any special cases, this notation can be carried over to line bundles on $Y$.
Question 1 Is this statement more generally true, for higher codimension varieties $Y$ in $\mathbb{P}^n$? (via e.g. some Lefschetz theorem?)
Now for a given complex manifold $X$, we can associate to $X$ the structure sheaf $\mathcal{O}_X$, which is the sheaf of local holomorphic functions on $X$. I understand that there is a relationship between the space of sections of a vector bundle and a particular locally free sheaf.
Question 2 Can we directly associate $\mathcal{O}_X$ with a line bundle on $X$? Is there some statement about the degrees of the sections of this line bundle?
Question 3 I believe the sections of $\mathcal{O}_{\mathbb{P}^n}(k)$, which are elements in $H^0(\mathbb{P}^n, \mathcal{O}_{\mathbb{P}^n}(k))$, are homogeneous polynomials of degree $k$. This should mean that sections of $\mathcal{O}_{\mathbb{P}^n}$ are locally constant polynomials. The previous should then be true for $Y\subset \mathbb{P}^n$, so that $H^0(Y, \mathcal{O}_Y)$ is the space of locally constant polynomials on $Y$. Is this the case, and in general can we classify line bundles on projective varieties based on the degrees of their sections? Or is the more fundamental object the 'cocycle' associated with the transition functions of the local trivialization (for $\mathcal{O}_{\mathbb{P}^n}(k)$ these are the $k$-th power of the transition functions of $\mathcal{O}_{\mathbb{P}^n}(1)$)?
Question 4 Is it correct to call the sheaf of sections of $\mathcal{O}_{\mathbb{P}^n}$ the structure sheaf of $\mathbb{P}^n$? How can this be if $\mathcal{O}_X$ is supposed to include all holomorphic functions, not just locally constant ones? In particular my confusion arises in the description of the exponential sequence, where the locally constant sheaf is called $\mathbf{Z}$, what is this objects relation to line bundles? (... of course this could just refer to the sheaf of integer valued functions?)
Sorry for the length, I believe these are all essentially different versions of the same question: what is the relationship of $\mathcal{O}_X$ to line bundles and sections of line bundles on $X$. My confusion arises because in the literature there are (with good reason) jumps between the sheaf description and the vector/line bundle description.
Fundamentally, $\mathcal O_X$ is the sheaf of sections of the trivial line bundle $\pi: X \times \mathbb C \to X$, where given a function $f \in \mathcal O_X(U)$ we have a section $U \to U\times \mathbb C$ given by the formula $x \mapsto (x,f(x))$. To somewhat answer question 1), injectivity of the restriction map on Picard groups seems to be true in a tremendous amount of generality (Kleiman, Toward a numerical theory of ampleness, Cor. 2 on p. 305). So while there may be line bundles on $Y$ not of the form $\mathcal O_Y(k)$, these bundles will always be distinct and you can use that notation without worry.
I have partially answered 2) already; regarding degrees, keep in mind that there is only an intrinsic notion of "degree" of a line bundle/its sections when a) $X$ is a curve, so the zeroes and poles are finite and we can just count them, or b) when $X$ is polarized, that is to say equipped with a choice of ample class $H$; then we can define $\deg(L) = H^{n-1}.L$.
For 3), I've never totally internalized how this works, but keep in mind that the sections of $\mathcal O_{\mathbb P^n}(k)$ are not literally homogeneous polynomials, rather they are canonically in bijection with them. The sections of $\mathcal O_{\mathbb P^n}$ on an open set $U$ are not exactly "locally constant polynomials," rather they are degree $0$ rational functions defined everywhere on $U$. So if $U = \left\{ x_0 \ne 0 \right\}$, you can get a section of $\mathcal O$ from any homogeneous polynomial $F(x_0,x_1,...,x_n)$ of degree $k$, namely $F/x_0^k$. More generally, the sections of $\mathcal O$ on a distinguished open $D(g)$ are of the form $F/g^k$, where $\deg(F) = k\cdot \deg g$. The ultimate point is of course that on the whole projective space, the only valid denominators are constants, hence (in order to keep the degree $0$) the only valid numerators are also constants. This should explain why $\mathcal O$ is the structure sheaf, and hopefully clears up why the constant sheaf $\mathbf Z$ is a different object (in particular not a line bundle).