w3resource

Python: Check whether Python shell is executing in 32bit or 64bit mode on OS

Python Basic: Exercise-42 with Solution

Write a Python program to determine if a Python shell is executing in 32bit or 64bit mode on OS.

Sample Solution-1:

Python Code:


# For 32 bit it will return 32 and for 64 bit it will return 64
import struct
print(struct.calcsize("P") * 8)

Sample Output:

64  

Sample Solution-2:

Python Code:

import platform, struct
print(platform.architecture()[0])
print(struct.calcsize("P") * 8)

Sample Output:

64bit
64

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to check whether a file exists.
Next: Write a Python program to get OS name, platform and release information.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

List comprehension:

>>> m = [x ** 2 for x in range(5)]
>>> m
[0, 1, 4, 9, 16]