How do I check what version of Python is running my script?

PythonServer Side ProgrammingProgramming

Python version is displayed on console immediately as you start interpreter from command line

Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Version information is present in version attribute defined in sys module

>>> import sys
>>> sys.version
'3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]'

Another attribute version_info is more elaborate. It provides major, minor and micro version levels.

>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=6, micro=1, releaselevel='final', serial=0)

There is also hexversion attribute which provides a unique number associated with the version. If converted using hex() function, it indicates the version.

>>> sys.hexversion
>>> hex(50725360)

Published on 30-Jan-2018 00:03:14