Python Convert Kilometers to Miles

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.


Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.