Python Convert Kilometers to Miles

Published: Apr 27, 2022

In this snippet, we will learn how to convert kilometers to miles in Python.

The Example

Let's have a look at the example:

kilometers = 2.5

# conversion factor
conv_fac = 0.621371

# calculate
miles = kilometers * conv_fac
print('%0.2f kilometers = %0.2f miles' %(kilometers, miles))

You can also run the program in our IDE.