Press "Enter" to skip to content

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

  1. Start
  2. Import struct module
  3. Use the calcsize(ā€œPā€) function to get the number of bytes required to store a single pointer
  4. Multiply the result by 4 if you have a 32-bit system else by 8 for a 64-bit system
  5. Display the output

Program

import struct
print("32 bit system : ",struct.calcsize("P")*4)
print("64 bit system : ",struct.calcsize("P")*8)
Freshers Placement

Output

32 bit system :  32
64 bit system :  64

Comments are closed.