Unit content
Pressure-volume boundary work with varying pressure
When pressure-volume work occurs while the pressure changes during a process, the constant-pressure expression $W=p_{\mathrm{ext}}\Delta V$ must be generalized by accumulating many small work contributions.
For a sufficiently slow expansion or compression, the pressure opposing the moving boundary can be treated as well defined throughout the process. A small volume change $dV$ contributes
$$dW=p,dV.$$
Accumulating from the initial to the final volume gives
$$\boxed{W_b=\int_{V_1}^{V_2}p,dV}.$$
On a $p$-$V$ diagram, this boundary work is the signed area under the process path.
Under the convention $\Delta U=Q-W$, expansion has $dV>0$ and gives positive work by the system; compression gives negative boundary work.
Constant-pressure case
If $p$ is constant, it can be taken outside the integral:
$$W_b=p\int_{V_1}^{V_2}dV =p(V_2-V_1),$$
recovering the constant-pressure result.
For example, if a gas expands at constant $200,\mathrm{kPa}$ from $0.10$ to $0.30,\mathrm{m^3}$,
$$W_b=200(0.20)=40,\mathrm{kJ}.$$
The path matters. Two processes can connect the same endpoint states while tracing different pressure-volume curves, producing different boundary work even though their change in internal energy is the same. Work is therefore a process quantity rather than a state property.