How to check the python version?

This article discusses the different methods to check the python version in the different operating systems and python scripts.

Checking python version in the different operating system( Windows, Mac, Linux)

Windows

  • Open Command Prompt.
  • Execute the command python --version or python -V or python -VV.
  • Example Output Python 3.9.0.python-version-command-prompt

Mac

  • Open Terminal.
  • Execute the command python --version or python -V or python -VV.
  • Example Output Python 3.9.0.

Linux

  • Open Bash.
  • Execute the command python --version or python -V or python -VV.
  • Example Output Python 3.9.0.

Checking python version in the Python script

The python version can be known by importing sys module or platform module.

1. By importing sys Module
  1. Open Python Script.
  2. Import sys module by executing import sys in python script.
  3. Follow any one of the following steps.
  • Execute sys.version() to get Information in a string format.python-version-sys
  • Execute sys.version_info to get information in a tuple format.python-version-sys
2. By importing platform module
  1. Open Python Script.
  2. Import platform module by executing import platform in python script.
  3. Follow any one of the following steps.
  • Execute platform.python_version() to get information in a short string format.python-version-platform
  • Execute platform.python_version_tuple() to get a short tuple infopython-version-platform-version-tuple
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions