Python: Print Version String from Script
Print version from the command line
python --version
Print version number from within the script
import sys print(sys.version) # 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] # path of the python interpreter print(sys.executable) # C:\Python39\python.exe
Printing version from script is a important technique to find out
which version your script is running. Because, you might have several
version installed, and in terminal, there are aliases, links, path
environment variables, various shell init scripts, that effect which
Python version will start when you type python
in shell.