Is there a way to find out the Python version inside the Python code?

Asked 1 years ago, Updated 1 years ago, 95 views

Is there a way to find out the version of Python interpreter in the script?

python version

2022-09-22 22:33

1 Answers

The functionality is implemented in the sys module.

import sys

#Comfortable for people to see
print "--sys.version--"
print sys.version

print "\n--sys.version_info--"
print sys.version_info

print "\n--sys.hexversion--"
print sys.hexversion

If you want to make a script work only on certain versions or higher, write as follows.

assert sys.version_info >= (2, 5) #2.5 and later only
ASSERT sys.version_info >= (3, 5, 0) #3.5.0 and later only

AssertionError occurs if it is below a certain version.


2022-09-22 22:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.