Pythondex
Python Conversion Programs

Convert MB To Bytes In Python

Last updated January 31, 2024 by Jarvis Silva

Looking for a python tutorial on how to convert mb to bytes in python then you are at the right place, In this tutorial we will see how can we convert megabytes to bytes using python programming.

To do this program it is very easy we just need to multiply mb with bytes in 1 mb which is 1000000 bytes, below is an example working of this program.


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

Python Code To Convert MB To Bytes


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

result = mb * b

print(f"{result} bytes")

Above is the code to convert mb to bytes format, as you can see in the code I have hardcoded the bytes of 1 MB then multiply it by what the MB’s user enters.

To run this program you can use this online python compiler or you can run it on your machine, 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

As you can see we successfully converted the mb to bytes format, I hope you found this tutorial helpful and useful, below 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 🙂