Nuclear power is the only way to make submarines work underneath the water for long distances without coming up because of the oxygen that all other types require.
And batteries for electric engines are too heavy.
Historically a submarine had to go up to just below sea level to get air through the snorkel for the engines that charge the batteries.
Then it could go down and drive only as far as the batteries could get and then repeat the process. But because the batteries are huge and heavy, this is only a short distance.
Under water the diesel engines do not work, they need the oxygen out of the air.
This was a huge disadvantage at war times.
Nuclear power does not need the fresh air (the oxygen part of it) like all other types of generators that work with combustion engines, which need oxygen. So someone built a nuclear submarine and this was so superior to the old ones that they chose to do it. They can travel and hide for months without coming up.
Some military ships are also nuclear powered:
It allows them to travel longer distances without refueling.
For civilian ships it is probably too expensive.
For air planes it seems easier and safer and cheaper, compared to nuclear power, to just power them with kerosene. A reactor is heavy and has a certain size. Large ships can carry them.
Submarines and ships have unlimited water cooling available.