To check which bit version the Python installation on your operating system supports, simply run the command “
python” (without quotes) in your command line or PowerShell (Windows), terminal (Ubuntu, macOS), or shell (Linux). This will open the interactive Python mode. The first line provides information whether it’s a 32 bit or 64 bit version.
Alternatively, you can also run the command “
py” if the command “
python” is not in your environment variable on your Windows machine.
Here’s the output on my computer (PowerShell) that shows that Python runs in a 64-bit version in the part
[MSC v.1928 64 bit (AMD64)]:
PS C:\Users\xcent> python Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
And here’s a screenshot:
In some environments such as macOS or some Linux versions, you may not see the number of bits in the output. You can manually output this using the
>>> import sys >>> sys.version '3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]'
Arithmetic Way to Check Bit Version
You can also calculate it manually in a small two-liner Python script:
import struct print(struct.calcsize("P") * 8)
The output is either
"64" depending on whether you run a 32-bit or 64-bit Python version:
# Output: # "32" for a 32-bit installation, or "64" for 64-bit
Here’s the explanation of the arithmetic approach to calculate the Python bit version:
struct module converts data between Python values and C structs using Python
bytes objects. The string argument
"P" represents a generic pointer in C. Here’s the gist: a pointer has 4 bytes on a 32-bit system, and 8 bytes on a 64-bit system. The
calcsize() function calculates the number of bytes for the pointer and multiplies it with 8 because 4*8 = 32 for a 32-bit system and 8*8 = 64 for a 64-bit system. Thus,
struct.calcsize("P") returns your “Python Bit Version”.
Where to Go From Here?
Enough theory. Let’s get some practice!
Coders get paid six figures and more because they can solve problems more effectively using machine intelligence and automation.
To become more successful in coding, solve more real problems for real people. That’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?
You build high-value coding skills by working on practical coding projects!
Do you want to stop learning with toy projects and focus on practical code projects that earn you money and solve real problems for people?
🚀 If your answer is YES!, consider becoming a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.
If you just want to learn about the freelancing opportunity, feel free to watch my free webinar “How to Build Your High-Income Skill Python” and learn how I grew my coding business online and how you can, too—from the comfort of your own home.
While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.