Home » 
        Python » 
        Python Programs
    
    Python program to print the version information
    
    
    
    
        Here, we are going to learn how to print the version information in Python programming language?
        
            By IncludeHelp Last updated : January 12, 2024
        
    
    Printing the Python version
    To print the Python version, use sys.version attribute of sys module. It returns a string that contains the version number of the Python interpreter, build number, and compiler used.
    Printing the Python version information
    To print the version information, use sys.version_info attribute, which can be used after importing the sys module, it returns a tuple containing some components of the version number: major, minor, micro, releaselevel, and serial.
    Python program to print the version information
# Python program to print the 
# version information
# importing the module
import sys
# printing version
print("Python version:\n", sys.version)
# printing version information
print("Python version info:\n", sys.version_info)
print("Python version info[0]: ", sys.version_info[0])
print("Python version info[1]: ", sys.version_info[1])
print("Python version info[2]: ", sys.version_info[2])
print("Python version info[3]: ", sys.version_info[3])
print("Python version info[4]: ", sys.version_info[4])
Output
The output of the above program is:
Python version:
 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]
Python version info:
 sys.version_info(major=3, minor=10, micro=6, releaselevel='final', serial=0)
Python version info[0]:  3
Python version info[1]:  10
Python version info[2]:  6
Python version info[3]:  final
Python version info[4]:  0
    Python Version Information Explanation
    Consider the above output, following version information we got.
    By using sys.verion attribute:
    
        - Version number: 3.10.6
- Build number: main, Nov 14 2022, 16:10:14
- Compiler used: GCC 11.3.0
By using sys.verion_info attribute:
    
        - Major: 3
- Minor: 10
- Micro: 6
- Release level: 'final'
- Serial: 0
To understand the above program, you should have the basic knowledge of the following Python topics:
    
    Python Basic Programs »
    
    
    
    
    
    
  
    Advertisement
    
    
    
  
  
    Advertisement