4. If $0<x<\frac{\pi}{2}$, then the range of $\operatorname{tg} x+\operatorname{ctg} x+\frac{1}{\sin x}-$ $\frac{1}{\cos x}$ is ().
(A) $(-\infty,+\infty)$
(B) $(0,+\infty)$
(C) $\left(\frac{1}{2},+\infty\right)$
(D) $(1,+\infty)$
4. (D) .
$$
\begin{array}{l}
f(x)=\frac{1+\cos x}{\sin x}+\frac{\sin x-1}{\cos x} \\
\frac{\cos x+\cos ^{2} x+\sin ^{2} x-\sin x}{\sin x \cos x} \\
=\frac{1+\cos x-\sin x}{\sin x \cos x}=\frac{2 \cos ^{2} \frac{x}{2}-2 \sin \frac{x}{2} \cos \frac{x}{2}}{2 \sin \frac{x}{2} \cos \frac{x}{2} \cos x} \\
=-\frac{\cos \frac{x}{2}-\sin \frac{x}{2}}{\sin \frac{x}{2}\left(\cos \frac{x}{2}-\sin \frac{x}{2}\right)\left(\cos \frac{x}{2}+\sin \frac{x}{2}\right)} \\
=-\frac{1}{\sin \frac{x}{2}\left(\sin \frac{x}{2}+\cos \frac{x}{2}\right)} \\
=\frac{1}{\sqrt{2} \sin \frac{x}{2} \sin \left(\frac{x}{2}+\frac{\pi}{4}\right)} \text {. } \\
\end{array}
$$

It is strictly decreasing, and its range is $(1,+\infty)$. (For this problem, simplifying the original function is necessary).