Sobes.tech
Intern

How do you find out the Python version?

sobes.tech AI

Answer from AI

// Check Python version from a script
import sys

print(sys.version)
# Check Python version from the command line
python --version
# Check Python version from the command line (alternative)
python -V

The simplest way to find out the Python version without running a script is to use the --version or -V flag when calling the interpreter from the command line. If Python is installed and available in PATH, the command python --version (or python -V) will display information about its version.

If you need to programmatically find out the Python version inside a running script, you can use the sys module. The attribute sys.version contains a string with full information about the interpreter version, including the version number, build info, and compiler used. The attributes sys.version_info (a tuple) and sys.hexversion (an integer) also provide version information, but in a different format, which can be useful for version comparisons.