How to Check Your Python Version?

A popular programming language, Python is used in effectively every field of science, including AI, IoT, ML, etc. Python provides multiple versions on their official website for its users. Sometimes to check the compatibility of any module or package, we need to check the version of Python 

This post will discuss various methods that are used to check Python versions in windows, Linux, and macOS. 

How to Check the Python Installed Version on Windows?

There are multiple methods available in windows to check your installed Python version. First, look at the below-given method:

Method 1: Using Python -V Command in CMD

Open the cmd terminal by pressing the (Windows key + R) button and typing the “cmd” in the run dialog box. After opening the cmd, type the below command to check the installed Python version:

python -V

Method 2: Using sys.version Method

We can also check the Python version by using the “sys.version” function of the “sys” module. In the example given below, the “sys.version” return the installed Python version:

Code: 

import sys
print(sys.version)

In the above code, first, the “sys” module is imported into the program; after that, the “sys.version” function is used to get the currently installed Python version.

Output: 

Python Version “3.11.1” is installed in our system.

Method 3: Using Python_version() Function

The “platform” module also provides a function named “Python_version()” to check and verify the installed Python version.

Code: 

from platform import python_version
#checking the installed version of Python
print(python_version())

Output:

The output shows that Python Version “3.11.1” is installed in our system.

How to Check the Python Installed Version in Linux?

To check the Python version in Linux or Ubuntu, type the below command in a terminal window:

$ python3 --version

The above output shows the installed version of Python in our system.

How to Check Your Installed Version of Python on macOS?

To check the Python version installed on macOS, type the below command in a terminal window:

python3 --version

Python Version “3.8.2” is installed in our macOS.

Conclusion

To check the installed Python version in windows, you can use the “python -V” command,  use the “sys.version” method, and the “Python_version()” Function. You can use the “python3 –version” command in the terminal for Linux. Similarly, the “python –version” command is in a terminal window to check the Python version for macOS. This Python tutorial provides an overview of how to check your Python version in windows, Linux, and macOS.