Write a python program to get the python version you are using.
Python Basic: Exercise-2 with SolutionWrite a Python program to get the Python version you are using. Show
A string containing the version number of the Python interpreter plus additional information on the build number and compiler used. This string is displayed when the interactive interpreter is started. Version info: A tuple containing the five components of the version number: major, minor, micro, releaselevel, and serial. All values except releaselevel are integers; the release level is 'alpha', 'beta', 'candidate', or 'final'. The version_info value corresponding to the Python version 2.0 is (2, 0, 0, 'final', 0). The components can also be accessed by name, so sys.version_info[0] is equivalent to sys.version_info.major and so on. Note : 'sys' module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. Sample Solution: Python Code:
Sample Output: Python version 3.5.2 (default, Sep 10 2016, 08:21:44) [GCC 5.4.0 20160609] Version info. sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0) Check the Python version on command line: Python Code:
Using platform module: Python Code:
Python version as tuple (major, minor, patchlevel) of strings: Python Code:
Python Code Editor: Have another way to solve this solution? Contribute your code (and comments) through Disqus. Previous: Write a Python program to print the following string in a specific format (see the output). Python: Tips of the DayUnion Of Collections: To get a distinct combined set of two sets. a = {1,2,3} b = {3,4,5} c = a.union(b) In this article, we will learn the command to check the version of Python using Python script. Let's first have a quick look over what is a Python script. Python is a well known high-level programming language. The Python script is basically a file containing code written in Python. The file
containing the python script has the extension Check Python VersionLike much other software, Python too has several different versions released to date. After Python or any installation, one should check the version of the software that is running the script. Python uses There are different versions of Python, but the two most popular ones are Python 2 and Python 3. When looking at the version number, there are usually three digits to read:
Let us look over the commands to check the Python version. Check Python Version in LinuxMost modern Linux distributions come with Python pre-installed. To check the version installed, open the Linux terminal window and enter the given command:
Check Python Version in WindowsMost out-of-the-box Windows installations do not come with Python pre-installed. However, it is always a good practice to check the version. To check the version installed, open Windows Powershell or any Python editor, and enter the given command:
Check Python Version in MacOSIf you are using a macOS, check the Python version by entering the given command in the terminal:
In all the three version checks, you will an output somewhat like Python 3.5.2. As discussed above 3 is the major version, 5 is the minor version and 2 is the micro version. Use sys module to check Python version
Use platform module to check Python version
ConclusionIn this article, we learned to use a simple command How do you find the Python version you are using?Press CMD + Space to open Spotlight. Type “ terminal ” and press enter. Execute command : type python ‐‐version or python -V and press Enter . The Python version appears in the next line below your command.
How do I print a Python version from Jupyter notebook?To check the Python version in your Jupyter notebook, first import the python_version function with “ from platform import python_version “. Then call the function python_version() that returns a string with the version number running in your Jupyter notebook such as "3.7. 11" .
|