Python: Print Version String
Print version from the command line
python --version
Print Version String from Within the Script
import sys print(sys.version) # 3.12.7 (tags/v3.12.7:0b05ead, Oct 1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)] # path of the python interpreter print(sys.executable) # C:\Users\xah\AppData\Local\Programs\Python\Python312\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.