Python program to determine if a Python shell is executing in 32bit or 64bit mode on OS
To determine the mode of python shell use struct module. The struct.calcsize(‘P’) calculates the number of bytes required to store a single pointer. It returns 4 for a 32-bit system and 8 for a 64-bit system
Algorithm
- Start
- Import struct module
- Use the calcsize(“P”) function to get the number of bytes required to store a single pointer
- Multiply the result by 4 if you have a 32-bit system else by 8 for a 64-bit system
- Display the output
Program
import struct print("32 bit system : ",struct.calcsize("P")*4) print("64 bit system : ",struct.calcsize("P")*8)
Output
32 bit system : 32 64 bit system : 64