In 2017, there were 100,472 locomotives in the world. This includes electric locomotives, diesel locomotives, steam locomotives, hydrogen locomotives, and any other kind of locomotives.
If you want to know more, please go here. This data was sourced from the book Transportation and the Belt and Road Initiative, in which more data as well as the original primary sources of the data are available.