To check the Python version on a Windows, Mac, or Linux machine, you can use the following command at the command prompt or in a script:
1 2 |
Copy code<code>python --version |
This command will print the version of Python that is currently installed on your machine.
To check the Python version from a script, you can use the following code:
1 2 3 |
Copy code<code>import sys print(sys.version) |
This code will print the version of Python that is being used by the script.
It’s also important to note that you can have multiple versions of Python installed on the same machine. In this case, you may need to specify the path to the Python executable in order to check the version. For example:
1 2 |
Copy code<code>/usr/local/bin/python3 --version |
This command will print the version of Python 3 that is installed in the specified location.