Python is one of the most popular programming languages in the world, and it has multiple versions available for download. Depending on your use case, you may need to know which version of Python you have installed on your computer. In this article, we'll cover different methods on how to check the Python version installed on your system.
Checking the python version is very important for the developers because:
As different version has different features which can affect the compatibility of the code. If you are using any third-party libraries, they require a specific version of Python. Checking the version can help you ensure that your code and libraries will work as expected.
Checking your Python version can help you identify whether you need to update to a newer version to ensure the security of your system.
Sometimes, an error may occur because of a compatibility issue between Python versions or because of changes in the behavior of a function or module.
This will also help you to find the resources that are relevant to your version of python. Python provides many resources that apply to specific resources. So, knowing your python version will ensure that the resources you are using apply to your version.
How to check python version
Here we have three different methods to check the python version:
Using Command Line
Using IDE
Using Python Script
Method 1: Using the command line
The command line is the most common method for checking the version of Python installed on your computer. Follow these simple steps:
Step 1: Open a command prompt or terminal window.
Step 2: Type the command "python --version" (without quotes) and press Enter.
Step 3: The version of Python installed on your system will be displayed in the output.
Here is an example output of this command on a computer running Python 3.9:
Python 3.9.0
If you have multiple versions of Python installed on your computer, you can specify the version you want to use by typing "python3.x --version" (replace x with the version number) instead of just "python".
Method 2: Using IDLE
IDLE is an integrated development environment (IDE) that comes with Python. You can use it to write and run Python code. Follow these steps to check the version of Python installed on your computer using IDLE:
Step 1: Open IDLE.
Step 2: Click on "File" > "New File" to create a new Python file.
Step 3: Type the command "import sys; print(sys.version)" (without quotes) in the new file and save it.
Step 4: Run the file by clicking on "Run" > "Run Module" or pressing F5 on your keyboard. Step 5: The version of Python installed on your system will be displayed in the output.
Here is an example output of this command on a computer running Python 3.9:
3.9.0 (tags/v3.9.0:9cf6752276, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
Method 3: Using a Python script
You can also use a Python script to check the version of Python installed on your computer. Follow these steps:
Step 1: Create a new Python file, and add the following code:
import platform
print(platform.python_version())
Step 2: Save the file with a .py extension, such as "check_python_version.py".
Step 3: Run the script by opening a command prompt or terminal window, navigating to the directory where the script is saved, typing "python check_python_version.py" (without quotes) and press Enter.
Step 4: The version of Python installed on your system will be displayed in the output.
Conclusion
In this article, we covered four methods to check the version of Python installed on your system. Using the command line, IDLE, a Python script, and Anaconda, you can easily find out which version of Python you have installed. No matter which method you choose, make sure you have a clear understanding of the version of Python you are working with before starting any projects.
تعليقات