How to Check Python Version

Hey there, welcome to my blog! In this post, I’m going to show you how to check your Python version in different ways.

Why is this important? Well, because Python is constantly evolving and adding new features, so you might want to know which version you are using and if it’s compatible with the libraries and tools you want to use. Also, some Python code might not work on older or newer versions, so it’s good to be aware of that.

There are several methods to check your Python version, but I’ll focus on two of them: using the command line, and using the Python interpreter. Let’s get started!

Method 1: Using the command line

The easiest and quickest way to check your Python version is to use the command line. This works on any operating system that has Python installed. All you have to do is open a terminal window and type the following command:

python --version

This will print out the Python version you have on your system. For example, on my Windows 11 laptop, I get this output:

Python 3.12.1

If you have more than one version of Python installed, you might need to specify which one you want to check. For example, if you have both Python 2 and Python 3 installed, you can use these commands:

python2 --version
python3 --version

This will print out the versions of Python 2 and Python 3 respectively. For example, on my Macbook Pro, I get these outputs:

Python 2.7.16
Python 3.8.2

Method 2: Using the Python interpreter

Another way to check your Python version is to use the Python interpreter. This is a program that lets you run Python code interactively. You can launch it by typing Python in the command line, or by clicking on the Python icon if you have a graphical interface.

Once you are in the interpreter, you can check your Python version by typing the following code:

>>>import sys
>>>print(sys.version)

This will print out the same information as the command line method, but with some extra details. For example, on my Windows 11 laptop, I get this output:

3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]

The first part is the Python version, followed by the release date and the compiler used to build it.

You can exit the interpreter by typing exit() or pressing Ctrl+D.

Conclusion

In this post, I showed you how to check your Python version in two different ways: using the command line, and using the interpreter. I hope you found this useful and learned something new. If you have any questions or comments, feel free to leave them below. Thanks for reading and happy coding!

Stephen Mclin
Stephen Mclin

Hey, I'm Steve; I write about Python and Django as if I'm teaching myself. CodingGear is sort of like my learning notes, but for all of us. Hope you'll love the content!

Articles: 90

Leave a Reply

Your email address will not be published. Required fields are marked *