How to Check Python Version
Sometimes you may need to check the version of Python installed on your system. There are a few different ways to do this, depending on your operating system and how Python is installed. Here are some methods you can use:
Method 1: Using the Command Line
- Open the command prompt or terminal on your computer.
- Type the following command and press Enter:
shell
python --version
This will display the Python version installed on your system.
Method 2: Using the Python Interpreter
- Open the command prompt or terminal on your computer.
- Type the following command and press Enter to open the Python interpreter:
shell
python
- Once the Python interpreter is open, type the following command and press Enter:
python
import sys
print(sys.version)
This will print the Python version along with additional information.
Method 3: Using a Python Script
- Open a text editor and create a new file.
- Add the following code to the file:
python
import platform
print(platform.python_version())
Save the file with a .py extension, for example, python_version.py.
- Open the command prompt or terminal and navigate to the directory where you saved the file.
- Type the following command and press Enter:
shell
python python_version.py
The output will display the Python version.
These methods should work on most operating systems and Python installations. Use the one that is most convenient for you.