# Almost surely equal random variables and expectation

Let $X, Y$ be random variables defined on the same probability space $(\Omega, \mathcal{F}, P)$. I'm interested in seeing a proof for the following results:

a) If $P(X = Y) = 1$, then $E(X) = E(Y)$.

b) If $P(X \le Y) = 1$, then $E(X) \le E(Y)$.

It is intuitive that what happens in a set with probability 0 should not change the expectation because it is defined in terms of simple functions, but I don't know how to prove the results rigorously. Also, I would like to know whether there is any extra condition for this to hold (e.g. $E(|X|)$ and $E(|Y|)$ be finite).

I don't have a background in integration theory or graduate analysis, so I'm learning how to write proofs at the same time I'm learning probability theory.

Answer to (a): Define $Z=X-Y$. Then clearly $P(Z=0)=1$ and therefore $E(Z)=0$ hence $E(X)=E(Y)$.
Answer to (b): Define $Z=Y-X$. Then $P(Z\geq 0)=1$ and hence $E(Z)\geq 0$ which means $E(Y)\geq E(X)$.
Remark: In order to be able to write $E(Z)=E(X)-E(Y)$, $E(X)$ and $E(Y)$ should be finite.