You can use the sys library in order to check the version of your Python Interpreter:
import sys print (sys.version)
Here is an example of a version of the Python Interpreter:
3.8.2
Get the components of your version
If you want to get the components of your version, you may use:
import sys print (sys.version_info)
For our example, the 5 components are:
sys.version_info(major=3, minor=8, micro=2, releaselevel='final', serial=0)
Here is another way to get the components:
import sys major = sys.version_info.major minor = sys.version_info.minor micro = sys.version_info.micro releaselevel = sys.version_info.releaselevel serial = sys.version_info.serial print (major) print (minor) print (micro) print (releaselevel) print (serial)
As you can see, the 5 components are:
3
8
2
final
0
Additional way to construct the Python version
Optionally, you can construct the version of your Python Interpreter as follows:
import sys major = sys.version_info.major minor = sys.version_info.minor micro = sys.version_info.micro python_version = str(major) + '.' + str(minor) + '.' + str(micro) print (python_version)
As before, the Python version is 3.8.2:
3.8.2