$ python
Python 3.11.1 (main, Jan 4 2023, 23:41:08) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Is there a programmatic way of printing those two lines that get printed when python is started?
Note: Somehow related to Printing Python version in output but not exactly the same question.
>Solution :
You can do this with the following:
import sys
print(f'Python {sys.version} on {sys.platform}')
print('Type "help", "copyright", "credits" or "license" for more information.')
Test on Windows:
>python
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; print(f'Python {sys.version} on {sys.platform}'); print('Type "help", "copyright", "credits" or "license" for more information.')
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Test on Linux:
$ python3
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; print(f'Python {sys.version} on {sys.platform}'); print('Type "help", "copyright", "credits" or "license" for more information.')
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
I assume you really want this information so that you can introspect the environment your program is running on (and not just for the sake of printing this information), in which case I suggest you read the documentation for the platform module.