Explore

Close
Python Programs Share

Convert MB To Bytes In Python

Convert MB To Bytes In Python

Looking for a python tutorial on how to convert mb to bytes in python then you are at the right place, today I am going to show you how to convert mb to bytes in python programming so read till the end.

Converting mb to bytes in python is very easy and simple. I will show you step by step on how to do it. Now let’s see some examples of the program.


# EXAMPLE 1
INPUT: 4 MB
OUTPUT: 4000000 Bytes
# EXAMPLE 2
INPUT: 1.8 MB
OUTPUT: 1800000

Above are some examples of how this program will work. Now let’s see how to convert mb to bytes in python code.

Convert MB To Bytes In Python Code


mb = float(input('Enter amount of MB: '))
b = 1000000

result = mb * b

print(f"{result} bytes")

Above is the python code to convert mb to bytes format, copy it and paste it in a python file and run it. You can use an online python compiler to test.

After running the program it will ask you to enter an MB amount you want to convert then it will convert and print it in bytes value below is an example output


Enter amount of MB: 1.8
1800000.0 bytes

This program is very simple. I have hardcoded 1 MB value in bytes which is 1000000 then I multiply it with the amount of mb you want to convert.

Summary

This was a short tutorial on how to convert mb to bytes in python, I hope you found this tutorial helpful and useful here are more python tutorials you may find helpful and useful:

I hope you found what you were looking for and do share this tutorial with anyone who requires it and also join our Telegram channel for future updates.

Thanks for reading, have a nice day 🙂