Meaning of $\mathcal{O}_X$ and line bundle notation 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.
 A: Question 1: Assuming you mean "is $\renewcommand{\Pic}{\operatorname{Pic}} \Pic(Y)\cong \Bbb Z$" for either $Y$ a hypersurface or $Y$ of high codimension, the answer is no - consider any smooth curve of positive genus. The Picard group is then $\Bbb Z$ times the Jacobian variety.
The appropriate version of Lefschetz for this scenario is the following:

Lefschetz for Picard groups (Lazarsfeld, Positivity in Algebraic Geometry I, example 3.1.25): Let $X$ be a smooth projective variety of dimension $\geq 4$, and $D\subset X$ a reduced effective ample divisor. Then the restriction map $$\operatorname{Pic} X\to\operatorname{Pic} D$$ is an isomorphism.

Question 2: In algebraic geometry, typically one first defines a line bundle as an invertible sheaf or a locally free sheaf of rank one. With this definition, $\mathcal{O}_X$ is already a line bundle. You might be looking for the "geometric vector bundle" construction - there's an equivalence of categories between locally free sheaves and geometric vector bundles which realizes the total space of a locally free sheaf $E$ over a scheme $X$ as a scheme over $X$ which is locally isomorphic to $X\times\Bbb A^n$. In the case where we take $E=\mathcal{O}_X^n$, we just get $X\times\Bbb A^n$.
Question 3: If you're working over an algebraically closed field with a projective variety $Y$, it is true that $H^0(Y,\mathcal{O}_Y)$ is locally constant functions on $Y$, which gives a vector space of dimension the number of connected components of $Y$. If you're working with projective varieties over a non-algebraically-closed field or a more general ring, more interesting things can happen. (And of course this all goes out the window when you're talking about a general non-projective variety - you can have all sorts of things happening with the global sections of the structure sheaf on an arbitrary scheme.)
As for the second part of the question, transition functions for line bundles always capture the full story: $\operatorname{Pic} X\cong H^1(X,\mathcal{O}_X^*)$ for any ringed space and the proof runs through using transition functions to define an element of the Čech cohomology (see for instance Hartshorne exercise III.4.5). It's less clear what you mean with regards to classifying line bundles "by the degree of their sections". Different embeddings can produce different degrees, and such a construction depends on the embedding of $Y$ in to some projective space: consider embedding $\Bbb P^1$ in to $\Bbb P^1$ by $\mathcal{O}(1)$ or $\Bbb P^2$ by $\mathcal{O}(2)$. (It's also not true that every sheaf is of the form $\mathcal{O}(k)$, which will further hamper your efforts here.)
Question 4: Everyone in algebraic geometry knows $\mathcal{O}_X$ as the structure sheaf, and some folks think about the sheaf of sections (not everybody - at the risk of revealing my own provincialism, I mostly work in places where the sheaf of sections approach is not typically useful for the problems I'm solving). There are many non-constant sections, you just have to look in the right places for them: for instance, if $U_0\subset\Bbb P^1$ is the complement of $[0:1]$, then $\mathcal{O}_{\Bbb P^1}(U_0)=k[x_1/x_0]$, which has non-constant sections.
The locally constant sheaf $\textbf{Z}$ is exactly the sheaf of locally constant integer-valued functions. It's an object of the category of sheaves of abelian groups on $X$, but not generally an object of the category of $\mathcal{O}_X$-modules, where most of algebraic geometry's dealings with sheaves takes place.
Meta-question: Line bundles are things that everywhere locally look like $\mathcal{O}_X$, in either the sheaf or sheaf of sections approach. The two approaches, sheaves and vector bundles, are equivalent - but it sounds like you need a bit more experience distinguishing between the two to really feel comfortable.
A: 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).
