You can check the version of Python that is running by using the standard module sys.
First, you need to import the sys module. Since it is a standard module, you do not need to install externally.
import sys print(sys.version_info)
The following is the output showing the current version of Python. It is Python 3.10.
sys.version_info(major=3, minor=10, micro=0, releaselevel='final', serial=0)
You can also run a if statement to check whether a version is older than a certain version. As mentioned in the dictionary tutorial, it is important to check Python version when using Python.
if sys.version_info >= (3, 7): print('Your Python is 3.7 or newer than 3.7.') else: print('Pleaes update your Python as it is older than 3.7.')
The following is the output:
Your Python is 3.7 or newer than 3.7.
You can also use the sysconfig module to print the information.
import sysconfig print(sysconfig.get_python_version())
The following is the output showing the current Python version.